C# 实体框架上下文有0个结果

C# 实体框架上下文有0个结果,c#,asp.net-mvc,entity-framework,wcf,dbcontext,C#,Asp.net Mvc,Entity Framework,Wcf,Dbcontext,我正在尝试调用我的实体framwork模型,并将结果返回到我的WCF服务 WCF服务方式 public User GetUser(string username, string password) { User userProfile = null; try { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { throw

我正在尝试调用我的实体framwork模型,并将结果返回到我的WCF服务

WCF服务方式

public User GetUser(string username, string password)
{
    User userProfile = null;
    try 
    {
        if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
        {
            throw new Exception("Username and password is null or empty");
        }
        var context = new InventoryManagerEntities();
        var userContext = (from user in context.Users
            where
                user.usr_Username.Equals(username, StringComparison.CurrentCultureIgnoreCase) &&
                user.usr_Password.Equals(password, StringComparison.CurrentCultureIgnoreCase)
            select user).
            FirstOrDefault();

    }
    catch (Exception exception)
    {
        throw exception;
    }
    return userProfile;
}
这个问题是我的上下文在每个实体对象中都没有数据。例如,用户有0个结果,但在SQLServer中,我可以看到我的表中有数据

顺便说一句,我的实体项目位于同一解决方案中的不同项目中,我不确定这是否与此有关

EF项目连接字符串 我在我的WCF项目中也使用相同的连接字符串。Sql Server管理工具中我的数据库的名称是
InventoryManager

    <add name="InventoryManagerEntities" 
         connectionString="metadata=res://*/InventoryManagerDBModels.csdl|res://*/InventoryManagerDBModels.ssdl|res://*/InventoryManagerDBModels.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=JUNIORLABOLD4A3\SQLEXPRESS;initial catalog=InventoryManager;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
  </connectionStrings>

您必须将ConnectionString添加到每个项目中。在Web.config或App.config中

如果您的项目没有这两个文件中的一个,只需创建它。但我确信,不加载任何结果的项目与实体项目具有不同的connectionString


您必须知道,MVC项目通常会自动创建连接字符串。检查一下

这可能是数据库上下文配置的问题。如果不按用户名和密码过滤,结果是否为空?如果这是真的,那么您的映射是错误的,错误出现在实体项目配置上。我认为这不会改变任何东西,我也尝试过使用user.usr\u Password==密码语法,但没有返回任何东西,问题是EF中所有my表的上下文计数为0,而数据库本身@LuisBecerrilWhy有数据您为什么要实现自己的(糟糕的)身份验证服务?其中有4个你可以使用它们来做正确的密码散列和盐析。最重要的是,您正在以不区分大小写的方式比较密码?真的吗?@RobertMcKee这不是现在的重点。。。我只是尝试返回数据,并从wcf@ifelabolz对不起,我更新了我的评论