Entity framework 5.0 with first MySQL code in WPF

This walkthrough works great with SQL Express: http://msdn.microsoft.com/en-us/library/gg197522(v=VS.103).aspx

I would like it to work with MySQL. I did some research, but none of the methods I found could do this for me. Ideally, I would like to do something like this:

      <entityFramework>
    <defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
  </entityFramework>

This does not work (I have MySQL Connector Net 6.5.4 installed and a link to MySql.Data). I tried to get an IDbConnection factory, as shown in this class here: http://www.vworker.com/RentACoder/misc/BidRequests/ShowBidRequest.asp?lngBidRequestId=1563829

and then using:

      <entityFramework>
<defaultConnectionFactory type="SchoolModel.MySqlConnectionFactory, SchoolModel" />

but it doesn’t work either. Can someone please give me some guidance on how to make this work?

.

+5
3

Connector 6.5.4 EF5 VS2012, :

  • MySql Connector 6.5.4 msi
  • VS2012 x86 :

    gacutil/i "C:\Program Files (x86)\MySQL\Connector NET 6.5.4\Assemblies\v4.0\mysql.data.dll" gacutil/i "C:\Program Files (x86)\MySQL\Connector NET 6.5.4\Assemblies\v4.0\mysql.data.entity.dll"

  • App.config <configuration>:

    <system.data> 
        <DbProviderFactories> 
            <remove invariant="MySql.Data.MySqlClient" />
            <add  
                name="MySQL Data Provider"
                invariant="MySql.Data.MySqlClient"
                description=".Net Framework Data Provider for MySQL"
                type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, 
                Version=6.5.4.0, Culture=neutral, 
                PublicKeyToken=c5687fc88969c44d"
            /> 
        </DbProviderFactories> 
    </system.data>
    
  • MySql.Data MySql.Data.Entity , ( MySqlConnection, MyDbContext)

    public class MyDbContext : DbContext
    {
        public MyDbContext(DbConnection connection) : base(connection, true) { }    ​
    
        public DbSet<Product> Products { get; set; }
    }
    
    [Table("sund_jshopping_products")]
    public class Product
    {
        [Key]
        [Column("product_id")]
        public int Id { get; set; }
        [Column("product_ean")]
        public string Ean { get; set; }
        [Column("product_manufacturer_id")]
        public int OperatorId { get; set; }
        [Column("months_status")]
        public string MonthsStatus { get; set; }
        [Column("extra_field_5")]
        public string SideId { get; set; }
    }
    
+3

MySQL db. , , " " , .

enter image description here

enter image description here

0

Connector 6.5.4 does not support code first with EF 5. In fact, it does not support code in the first place.

You can try using a network connector (at least a trial version).

0
source

All Articles