Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架查询错误_C#_Entity Framework - Fatal编程技术网

C# 实体框架查询错误

C# 实体框架查询错误,c#,entity-framework,C#,Entity Framework,为什么这样做有效: List<Item> items = ndb.Items.Where(m => m.ProductId == id).OrderByDescending(m => m.Id).ToList(); int itemid = items[0].Id; bool wlexists = ndb.Wishlists.Any(m => m.ItemId == itemid && m.UserEmail == User.Identity.Nam

为什么这样做有效:

List<Item> items = ndb.Items.Where(m => m.ProductId == id).OrderByDescending(m => m.Id).ToList();
int itemid = items[0].Id;
bool wlexists = ndb.Wishlists.Any(m => m.ItemId == itemid && m.UserEmail == User.Identity.Name);
List items=ndb.items.Where(m=>m.ProductId==id).OrderByDescending(m=>m.id).ToList();
int itemid=items[0].Id;
bool wlexists=ndb.Wishlists.Any(m=>m.ItemId==ItemId&&m.UserEmail==User.Identity.Name);
但这并不是:

List<Item> items = ndb.Items.Where(m => m.ProductId == id).OrderByDescending(m => m.Id).ToList();

bool wlexists = ndb.Wishlists.Any(m => m.ItemId == items[0].Id && m.UserEmail == User.Identity.Name);
List items=ndb.items.Where(m=>m.ProductId==id).OrderByDescending(m=>m.id).ToList();
bool wlexists=ndb.Wishlists.Any(m=>m.ItemId==items[0].Id&&m.UserEmail==User.Identity.Name);

如果
具有值,即不为空,则它必须工作。你得到了什么错误

像这样做

List items=ndb.items.Where(m=>m.ProductId==id).OrderByDescending(m=>m.id).ToList();
如果(项!=null)
bool wlexists=ndb.Wishlists.Any(m=>m.ItemId==items[0].Id&&m.UserEmail==User.Identity.Name);

我看不出第二个查询不起作用的原因,您得到的异常是什么?