0
我有一個潛在的簡單問題。我的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;
}
錯誤是什麼? –
我實際上沒有收到錯誤,當數據庫中有數據時,所有結果都會返回null。這很奇怪。 – user5792975
您必須將連接字符串添加到導入庫項目 –