【发布时间】:2013-03-15 20:39:30
【问题描述】:
我有一个场景,其中一个方法将采用 Func 类型的谓词,因为 T 类型是暴露给外部世界的类型,但在实际使用该谓词时我需要该方法来调用另一个方法,该方法将采用 Func 其中 T 的属性映射到 U 的属性。
一个更具体的例子是:
public IEnumerable<ClientEntity> Search(Func<ClientEntity, bool> predicate)
{
IList<ClientEntity> result = new List<ClientEntity>();
// Somehow translate predicate into Func<Client, bool> which I will call realPredicate.
_dataFacade.Clients.Where(realPredicate).ToList().ForEach(c => result.Add(new ClientEntity() { Id = c.Id, Name = c.Name }));
return result.AsEnumerable();
}
这可能吗?
请注意,ClientEntity 是我自己定义的 POCO 类,而 Client 是模型创建的实体框架类(DB 优先)。
谢谢!
【问题讨论】:
标签: linq entity-framework-4 linq-to-entities