3
为什么下面的LINQ to SQL语句会引发异常?为什么我不能在LINQ to SQL中重用函数
我有一个函数
bool TrimAndCompare(string s1, string s2)
{
return customer.CustomerID.Trim() == customerID.Trim()
}
...一些其他的功能,我所说的以上功能在我的LINQ声明
var customers = from customer in _context.Customers
where
TrimAndCompare(customer.CustomerID, customerID)
select customer;
以上的LINQ to SQL statment函数抛出一个异常 但下面不是为什么?
var customers = from customer in _context.Customers
where
customer.CustomerID.Trim() == customerID.Trim()
select customer;
我得到的“System.NotSupportedException” ,我尝试访问客户
好吧,如果我想要做的东西,是当我试图让一个布尔值回来,但什么好的。像 变种客户从客户=在_context.Customers 其中 customer.GetID()==“一” 选择顾客; – soldieraman 2010-01-21 08:07:29
@soldierman:该点是一个'Where'表达式* *不返回一个布尔值你是compo se作为查询的一部分 - 注意我所有的例子都调用了Where。重点是它创建一个表达式树,其中包含正确的逻辑,以便您可以将该表达式树包含在查询的其余部分中。 – 2010-01-21 08:17:09