Glimpse SQL显示经常选择前2名

时间:2014-06-12 11:58:23

标签: entity-framework glimpse

参见本例

enter image description here

现在我不做前2,我只是做一个简单的实体查找,所以我有点不知道为什么。

1 个答案:

答案 0 :(得分:3)

您很可能使用SingleOrDefaultFind。这些方法通过选择前两行来工作。然后确保只返回一行。如果返回了多个元素,那么它将抛出异常。

如果有多场比赛,怎么知道?

// If there were two Products with a ProductName of Widget then the code would throw an exception.
context.Products.SingleOrDefault(i => i.ProductName == "Widget");

// If there were two Products with a ProductId of 1234 then the code would throw an exception.
context.Products.Find(1234);