【发布时间】:2017-12-10 23:40:46
【问题描述】:
我提供了以下查询(简化版)以从我的服务返回 IQueryable:
var query =
(from item in _entityRepository.DbSet()
where
MyCondition
orderby Entity.EntityID descending
select new DTOModel
{
Id = Entity.EntityID,
...,
//My problem is here, when I trying to call a function into linq query:
//Size = Entity.IsPersian ? (Entity.EntitySize.ConvertNumbersToPersian()) : (Entity.EntitySize)
//Solution (1):
//Size = ConvertMethod1(Entity)
//Solution (2):
//Size = ConvertMethod2(Entity)
});
根据我的查询,我的服务类中还有以下代码:
//Corresponding to solution (1):
Func<Entity, string> ConvertMethod1 = p => (p.IsPersian ? p.EntitySize.ConvertNumbersToPersian() : p.EntitySize);
//Corresponding to solution (2):
Expression<Func<Entity, string>> ConvertMethod2 = (p) => (p.IsPersian ? p.EntitySize.ConvertNumbersToPersian() : p.EntitySize);
我看到了以下错误:
解决方案(1)对应的生成错误:
LINQ to Entities 不支持 LINQ 表达式节点类型“Invoke”。
解决方案(2)对应的生成错误:
这是一个编译错误: 需要方法、委托或事件
非常感谢任何高级帮助。
【问题讨论】:
标签: c# linq iqueryable func