0

我有一个非常大的问题:我正在尝试使用其他对象查找实体(使用 NHibernate)。示例: Emplyee (entity) -> { Name, LastName, Email, Address } EmplyeeSearchFilters (filters object) -> { Name, LastName, Email, Address } 然后,我想将 EmployeeSearchFilters 传递给 Repository (generic) 并自动查找NHibernate 使用不为空的属性。示例:EmployeeSearchFilters -> { Name = "Nelly", LastName = null, Email = "@fibertel.com", Addres = null } 有人知道我该怎么做吗?

谢谢!

4

2 回答 2

2

我认为该NHibernate.Criterion.Example标准可以用于此目的。文档可以在这里找到

于 2012-11-09T20:52:28.820 回答
1

您可以通过使用此功能来使用 linq:

    public virtual List<T> RetrieveByList<T>(Expression<Func<T, bool>> predicate)
    {
        return Session.Query<T>().Where(predicate).ToList<T>();
    }

并且可以这样使用:

    RetrieveByList<Customer>(x=>x.Name == "Nelly" && x.LastName == null && x.Email == "@fibertel.com" && x.Addres == null)

您可以使用动态谓词http://www.codeproject.com/Articles/28580/LINQ-and-Dynamic-Predicate-Construction-at-Runtime

于 2012-11-10T08:59:37.343 回答