我想知道是否有办法在 LINQ to Entities 中调用内置 sql 函数?比如'CAST'
,'ISNULL'
。我在网上搜索过,我知道如何在 LINQ to Entities 中调用用户定义的函数,但我不知道如何调用内置函数。当然,一些内置函数可以通过 CLR 方法代替,但如果您有办法直接调用它们,我将不胜感激。
问问题
956 次
1 回答
1
SqlFunctions 类- 提供公共语言运行时 (CLR) 方法,这些方法在 LINQ to Entities 查询中调用数据库中的函数。
如何使用
using (AdventureWorksEntities AWEntities = new AdventureWorksEntities())
{
// SqlFunctions.CharIndex is executed in the database.
var contacts = from c in AWEntities.Contacts
where SqlFunctions.CharIndex("Si", c.LastName) == 1
select c;
foreach (var contact in contacts)
{
Console.WriteLine(contact.LastName);
}
}
于 2012-08-08T08:25:05.050 回答