当我在 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 中无效?
最佳答案
你能不能这样试试
customerList = db.Customer.
Where(c => String.Compare (c.customerName.ToUpper(),"test".ToUpper()) == 0).ToList();
因为区分大小写搜索客户名称可能存在问题。
尝试其他变体:String.Compare Method根据您的需要
关于c# - 对 varchar 字段的 linq 查询不返回任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13950709/