当前位置: 移动技术网 > IT编程>开发语言>.net > .NET开发中基础问题,CODE First AND DB First(大牛自动忽略,小白可以看一下)

.NET开发中基础问题,CODE First AND DB First(大牛自动忽略,小白可以看一下)

2018年10月23日  | 移动技术网IT编程  | 我要评论

荆门龙泉中学,鼎盛王朝军事论坛,str6708

最近在做一个新项目开发时,碰到了下面这个问题.在使用ef时,提示错误信息

to continue using database first or model first ensure that the entity framework connection string is specified in the config file of executing application. to use these classes, that were generated from database first or model first, with code first add any additional configuration using attributes or the dbmodelbuilder api and then remove the code that throws this exception.

 

在网上也找了一些回复,但是基本都没有说明怎么解决的,我在这里说一下,

这个原因是因为web.config中配置的连接字符串决定的.不同的连接字符串是不一样的

下面这种字符串是code first的,

<add name="xxxx" providername="system.data.sqlclient" connectionstring="data source=xx.xx.x8.xx;initial catalog=xx;persist security info=true;user id=xx;password=xx;"/>

通过ef同步数据库的类,应该使用下面这种链接字符串

<add name="xx" connectionstring="metadata=res://*/xx.csdl|res://*/xx.ssdl|res://*/xx.msl;provider=system.data.sqlclient;provider connection string=&quot;data source=xx.xx.xx.xx;initial catalog=xx;persist security info=true;user id=sa;password=xx;multipleactiveresultsets=true;app=entityframework&quot;" providername="system.data.entityclient" />

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网