【发布时间】:2012-12-19 10:51:59
【问题描述】:
当我在 linqpad 中运行此查询时:
Customer.Where(c => (c.CustomerName == "test"))
它返回匹配的记录。
当我尝试在 visual studio 中运行相同的查询时,它不会返回任何匹配的记录。这是我正在使用的代码:
List<Customer> customerList = new List<Customer>();
using (DBEntities db = new DBEntities())
{
try
{
customerList = db.Customer.Where(c => (c.customerName == "test")).ToList();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
return customerList;
谁能明白为什么它在 linqpad 中有效,但在 visual studio 中无效?
【问题讨论】:
-
如果你调试,
db.Customer对象中是否有一堆对象,其中至少有一个带有“test”作为customerName?它看起来很简单,这是最简单的问题。 -
您的 VS 代码中有不同的
customerName大小写。我不知道这是否只是一个错字。此外,new List<Customer>()分配是多余的,因为它会被查询覆盖。 -
linqpad 对象名大写,VS 不改。
标签: c# linq visual-studio linqpad