类库中的实体框架为空

问题描述 投票:0回答:1

我有一个潜在的简单问题。我的EF代码获取除一个类库之外的每个项目中的数据。我的App.config文件中是否需要为此类库添加其他连接字符串?我从一个名为“models”的类库中提取所有数据,并为整个项目提供一个连接字符串。你有什么建议我这样做?也许这也是我本地数据库的问题。如果您需要更多信息,请与我们联系。

样品:

public static bool IsAdmin()
        {
            try
            {
                using (EmployeeContext _context = new EmployeeContext())
                {
                    string user = WindowsIdentity.GetCurrent().Name;

                    var adminCheck = (from u in _context.Administration where u.Login.Equals(user) select u).FirstOrDefault();

                    if (adminCheck == null)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
            }
            catch(Exception ex)
            {
                ErrorLogging.Record(ex.ToString(), ex.StackTrace);
            }
            return false;
        } 
c# sql database visual-studio entity-framework
1个回答
0
投票

在主应用程序中定义连接字符串,问题可能是(虽然我不确定)EF默认为localDB。

© www.soinside.com 2019 - 2024. All rights reserved.