EF连接MYSQL报错

jiaoshiyao 2014-11-04 11:40:15
我调了半天 实在调不出来了

Context出错


<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="LotteryContext" providerName="MySql.Data.MySqlClient" connectionString="Data Source=127.0.0.1;port=3306;Initial Catalog = LotteryContext;user id =root;password=081025160063;" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<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.9.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
...全文
105 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
smthgdin_020 2014-11-05
  • 打赏
  • 举报
回复
断点调试一下 entity.sysuserinfo,在即时窗口看看这是否为空。
sinat_22957135 2014-11-05
  • 打赏
  • 举报
回复
moonwrite 2014-11-05
  • 打赏
  • 举报
回复
还有 username 不用 tolower linq to ef因为数据库是不在乎大小写的 所以ling to ef是不用在乎大小写的 linq to object的时候就要在乎大小写了
moonwrite 2014-11-05
  • 打赏
  • 举报
回复
我的看法如同2楼 你断点 看看 entity 是不是空 不是空 那么就是username的问题 另外 命名问题 LotteryContext db = new LotteryContext entity 一般只EF搜索出来的一个实体
wjq 2014-11-04
  • 打赏
  • 举报
回复
我怎么觉得是你的传入参数UserName是null……
jiaoshiyao 2014-11-04
  • 打赏
  • 举报
回复
Seed方法内 我添加了100条数据 表示创建出来了 但是100条数据没填进去 然后 创建new Context出错

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧