entity wpf mysql,实体框架5.0代码首先与MySQL在WPF中

I would like it to work with MySQL. I've done some research but none of the techniques I've found has been able to do it for me. Ideally I would like to do something like this:

This doesn't work (I have MySQL Connector Net 6.5.4 installed & MySql.Data referenced). I've tried deriving from IDbConnection factory as shown in this class here:

http://www.vworker.com/RentACoder/misc/BidRequests/ShowBidRequest.asp?lngBidRequestId=1563829

and then using:

but that doesn't work either. Can anybody please give me some pointers as to how to get this to work?

Many thanks.

解决方案

To use Connector 6.5.4 with code-first EF5 on VS2012 you need:

Install MySql Connector 6.5.4 msi

Open VS2012 x86 Command Prompt as Admin and execute:

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"

Add in your project's App.config this code to section:

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"

/>

Now add references to MySql.Data and MySql.Data.Entity to your solution and some code like this (I create MySqlConnection, then pass it to constructor of MyDbContext)

public class MyDbContext : DbContext

{

public MyDbContext(DbConnection connection) : base(connection, true) { } ​

public DbSet 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; }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值