[英]System.NotSupportedException when trying to create an asset
[英]Entity System.NotSupportedException when querying with FirstOrDefault
我正在尝试检索唯一的元素(如果存在),或者如果没有则返回null。
我的职能是:
private Dealer GetOrCreateDealer(DataRow dataRow)
{
ModelCamwareContext localContext = new ModelCamwareContext();
string test = dataRow["Dealer"].ToString();
Dealer dealer = localContext.Dealers.Where(x => x.Name == dataRow["Dealer"].ToString()).FirstOrDefault();
if (dealer != null)
{
...
}
else
{
...
}
}
我的测试字符串就在这里,以确保dataRow信息没有问题,它可以按预期工作,并为我提供了我要选择经销商的字符串。
除非我弄错了,否则在没有经销商可以检索的情况下,FirstOrDefault不会给我任何例外,在这种情况下,我应该让Dealer = null。
我得到的例外:
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll
我错过了什么 ?
实体无法评估其LINQ中的数据表值。 尝试这样的事情:
ModelCamwareContext localContext = new ModelCamwareContext();
string test = dataRow["Dealer"].ToString();
Dealer dealer = localContext.Dealers.Where(x => x.Name == test).FirstOrDefault();
if (dealer != null)
{
}
else
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.