LINQ to Entities:数据库连接失败
我刚刚将数据访问从 Linq to SQL 转换为 Linq to Entities。我已经创建了我的 edms 并更新了我的类,如下所示,但我收到任何未找到连接的错误。 错误位于 ModelDesigner.cs 文件中。对此有什么帮助吗?谢谢〜susan〜
错误报告:
指定的命名连接未在 配置,不打算与 EntityClient 提供程序一起使用, 或无效。
Line 48: /// Initializes a new FVTCEntities object using the connection string found in the 'FVTCEntities' section of the application configuration file.
Line 49: /// </summary>
Line 50: public FVTCEntities() : base("name=FVTCEntities", "FVTCEntities")
Line 51: {
Line 52: this.ContextOptions.LazyLoadingEnabled = true;
这是我的数据访问层的代码:
namespace DL
{
public class DLgetRestaurants
{
FVTCEntities db = new FVTCEntities();
public List<RESTAURANT> getRestaurants(string cuisineName)
{
var cuisineID = db.CUISINEs.First(s => s.CUISINE_NAME == cuisineName).CUISINE_ID;
List<RESTAURANT> result = (from RESTAURANT in db.RESTAURANTs.Include("CITY").Include("CUISINE")
where RESTAURANT.CUISINE_ID == cuisineID
select RESTAURANT).ToList();
return result;
}
}
}
I've just converted my data access from Linq to SQL to Linq to Entities. I've created my edms and a have updated my class as follows but I'm getting any error that the connection is not found. The error is in the ModelDesigner.cs file. Any help on this? Thanks ~susan~
Error report:
The specified named connection is either not found in the
configuration, not intended to be used with the EntityClient provider,
or not valid.
Line 48: /// Initializes a new FVTCEntities object using the connection string found in the 'FVTCEntities' section of the application configuration file.
Line 49: /// </summary>
Line 50: public FVTCEntities() : base("name=FVTCEntities", "FVTCEntities")
Line 51: {
Line 52: this.ContextOptions.LazyLoadingEnabled = true;
Here is my code for my Data Access Layer:
namespace DL
{
public class DLgetRestaurants
{
FVTCEntities db = new FVTCEntities();
public List<RESTAURANT> getRestaurants(string cuisineName)
{
var cuisineID = db.CUISINEs.First(s => s.CUISINE_NAME == cuisineName).CUISINE_ID;
List<RESTAURANT> result = (from RESTAURANT in db.RESTAURANTs.Include("CITY").Include("CUISINE")
where RESTAURANT.CUISINE_ID == cuisineID
select RESTAURANT).ToList();
return result;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的连接字符串可能没有指定元数据资源。您可以发布您的连接字符串吗?
http://msdn.microsoft.com/en-us/library/cc716756.aspx
Chances are your connection string doesn't have the metadata resources specified. Can you post your connection string?
http://msdn.microsoft.com/en-us/library/cc716756.aspx