我想知道如何通过属性获取实体
我不想在传递实际的SQL查询时使用SqlQuery方法。Find()只处理pk值。
我希望能够在我的存储库中有一个方法,我可以在其中传递一个带有各自值的属性字典来过滤我的实体。
public IList<TEntity> FindByProperties(IDictionary<string,object> propertyValues)NHibernate提供了条件查询接口,EF有类似的功能吗?
请提个建议。谢谢
发布于 2012-11-04 20:35:36
在Entity Framework中,通常使用lambda表达式来创建过滤条件。你可以有一个方法..。
public IList<TEntity> FindByExpression(Expression<Func<TEntity, bool>> filter)
{
    return context.Set<TEntity>().Where(filter).ToList();
}...and这样称呼它:
...FindByExpression(t => t.Name == "Jim" && t.City == "Paris");https://stackoverflow.com/questions/13217953
复制相似问题