实体< t>找不到课程

编程入门 行业动态 更新时间:2024-10-28 21:29:19
本文介绍了实体< t>找不到课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用实体框架6.1作为wcf服务的默认连接字符串。我想在使用EF 6.1从数据库中获取用户登录时获取用户的详细信息。 但我面临的问题是没有连接到数据库和没有从数据库中获取数据。 我尝试过:

var objUser =(来自u in dbContext.Users ,其中u.UserName.Equals(user.UserName) select u).FirstOrDefault();

从这里我没有从数据库中获取数据说没有连接数据。 这里dbContext是一个对象数据库实体的实例,例如

公共部分类项目:DbContext {}

这个类来自edmx文件和projectentity对象dbContext在项目外的其他一些类中调用,但是它在同一个解决方案中.... 现在错误点我觉得这样...... 'dbContext.Us ers.Local'抛出类型'System.InvalidOperationException'的例外' 任何人都可以解释这一点。在此先感谢

解决方案

您在DBContext中遇到的错误与代码无关,连接字符串中应该有一些错误。 解决这个问题: 步骤1:检查web.config文件中的连接字符串 - >检查数据库上下文名称是否正确指定在C#DB上下文实体名称中。 步骤2:转到App.Config并且如果您有多个条目连接字符串保留最新的连接字符串并删除其他连接。 步骤3:检查App.Config和Web.Config中的连接字符串是否指向仪式数据库。 如果以上步骤工作, 尝试再次删除和添加edmx文件。这应该有效。 提前致谢:)

I used entity framework 6.1 for the default connection string from wcf service. In which i want to get the details of user when the user logins has taken from the database using EF 6.1. But i am facing problem not connecting to the database and not getting the data from the database. What I have tried:

var objUser = (from u in dbContext.Users where u.UserName.Equals(user.UserName) select u).FirstOrDefault();

From this i am not getting the data from the database saying the data has not been connected. Here dbContext is an object instance for the database entity like

public partial class projectentity : DbContext { }

this class is from edmx file and projectentity object dbContext called at some other class outside the project but it is in the same solution.... Now the error point of view i am getting like this... 'dbContext.Users.Local' threw an exception of type 'System.InvalidOperationException' Can anyone explain me this point. Thanks in advance

解决方案

The error you are getting in the DBContext has nothing to do with the code there should be some error in the connection string. To Solve this problem: Step 1: Check the connection string in the web.config file --> check the DB context name is correctly specified as in the C# DB context entity name. Step 2: Go to the App.Config and if you have multiple entries of the connection strings keep the latest one and delete the other connections. Step 3: Check if the connection string in the App.Config and Web.Config are pointing to the rite Database. If the above steps dint work, Try deleting and adding the edmx file again. That should work. Thanks in advance. :)

更多推荐

实体< t>找不到课程

本文发布于:2023-11-07 09:19:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566074.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   实体   课程   lt   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!