LINQ to Entities:数据库连接失败

发布于 2024-11-24 00:51:54 字数 1330 浏览 1 评论 0原文

我刚刚将数据访问从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慈悲佛祖 2024-12-01 00:51:54

您的连接字符串可能没有指定元数据资源。您可以发布您的连接字符串吗?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文