首页 > 其他 > 详细

Model-First和Code-First配置文件差异

时间:2015-12-03 02:20:43      阅读:273      评论:0      收藏:0      [点我收藏+]

    在使用EnityFramework时,使用Model-First和Code-First时,配置文件中连接字符串是有差异的。在使用ADO.NET实体数据模型向导时,基于数据库的EF设计器和基于数据库的Code-First都会在向导阶段设置所需的配置文件。而空的EF设计器,在模型生成好后,可以通过从模型更新数据库向导设置连接字符串。而对于空Code-First模型则需要在配置文件中修改数据库连接字符串中数据库的数据源。

    如果自己手动实现Code-First模式,则需要先通过NuGet安装EntityFramework。然后手动添加连接字符串。

连接字符串模板如下:

    <add name="EF6RecipesContext" connectionString="data source=(LocalDb)\MSSQLLocalDB;initial catalog=EF6Recipes;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />

    而Model-First的连接字符串为:

    <add name="EF6RecipesContext" connectionString="metadata=res://*/Recipe2.csdl|res://*/Recipe2.ssdl|res://*/Recipe2.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\mssqllocaldb;initial catalog=EF6Recipes;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />


本文出自 “ForMeForYou” 博客,请务必保留此出处http://tancfeng.blog.51cto.com/4079342/1719038

Model-First和Code-First配置文件差异

原文:http://tancfeng.blog.51cto.com/4079342/1719038

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!