ASP.NET Web开发+linq to Entities出现的问题
之前在Web开发中都是利用前台WebForm+后台三层架构以及Linq to Sql实现数据的增删查改,如今Linq to Sql已经不再维护,现在已经改成了Linq to Entities。不得不说的是,实际上Ling to Entities的语法和Linq to Sql差不多,只是数据库的变成了ADO.NET实体数据模型。
和与使用Linq to Sql查询数据后刷在WebForm里gridview上不同的是,在后台完成与数据库的连接之后(App.config里面的),还需要对前台的Web.config进行相同的配置。如果不做配置,则会出现以下错误:

所以,需要在Web Application中的Web.config进行配置,即将App.config中的如下配置复制粘贴在Web.config中即可
<connectionStrings>
<add name="BrWMSEntities" connectionString="metadata=res://*/DAL.Common.BrWMS.csdl|res://*/DAL.Common.BrWMS.ssdl|res://*/DAL.Common.BrWMS.msl;provider=System.Data.SqlClient;provider connection string="data source=lee;initial catalog=BrWMS;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
添加完以后又会出现以下问题:

解决办法:
在Web项目中添加nuget包EntityFramework.SqlServerCompact即可
本文介绍从Linq to Sql迁移至Linq to Entities的过程,详细说明了配置Web.config文件的方法,并解决了相关错误。同时提供了安装NuGet包EntityFramework.SqlServerCompact的解决方案。
457

被折叠的 条评论
为什么被折叠?



