我在我的网络应用程序中多次使用此代码,出于某种原因,这部分一直返回错误:Object reference not set to an instance of an object.
string username = "John";
using (TicketsEntities dbc = new TicketsEntities())
{
var usr = from cs in dbc.Logins
where cs.FullName == username
select cs;
DataModel.Login lgn = usr.SingleOrDefault<DataModel.Login>();
string user = lgn.Email;
lbler.Text = user;
}
我的数据库中只有一个名为“John”的条目。我已经测试了 null 但它一直给我错误string user = lgn.Email;