【发布时间】:2011-07-14 04:24:19
【问题描述】:
稍后在我的 EF 中,我试图传入一个匿名函数以用作我的 Linq 查询的一部分。该函数将传入一个 INT 并返回一个 BOOL(u.RelationTypeId 是一个 INT)。下面是我的函数的简化版本:
public IEnumerable<UserBandRelation> GetBandRelationsByUser(Func<int, bool> relation)
{
using (var ctx = new OpenGroovesEntities())
{
Expression<Func<UsersBand, bool>> predicate = (u) => relation(u.RelationTypeId);
var relations = ctx.UsersBands.Where(predicate);
// mapping, other stuff, back to business layer
return relations.ToList();
}
}
但是,我收到上述错误。通过从函数构建谓词,我似乎一切都正确。有任何想法吗?谢谢。
【问题讨论】:
标签: c# asp.net linq entity-framework linq-to-entities