0

我有一个项目列表,我可以在其中获取有关项目的所有详细信息。在项目类中,我在项目中有客户对象,我只想根据客户过滤该列表。我怎样才能做到这一点 。

public ICollection<Project> GetProjectBasicDetailsByProjectTypeCustomerID(ProjectType projectType, string custName, string cordinatorName, string projectName)
    {
        oLog.Debug("Started");
        ISession session = DataAccessLayerHelper.OpenReaderSession();
        ITransaction transaction = null;
        ICollection<Project> projectList = null;
        try
        {
            transaction = session.BeginTransaction();
            ICriteria criteria = session.CreateCriteria(typeof(Project),"Project")
                .CreateAlias("Project.customer","customer",NHibernate.SqlCommand.JoinType.InnerJoin)
                .CreateAlias("Project.Coordinator", "Coordinator", NHibernate.SqlCommand.JoinType.InnerJoin)
                .Add(Restrictions.Eq("Project.ProjectType", projectType));


            projectList = criteria.List<Project>().ToList();

            session.Flush();
            transaction.Commit();
        }
        catch (Exception ex)
        {
            if (transaction != null && transaction.IsActive)
                transaction.Rollback();
            oLog.Error(ex);
        }
        finally
        {
            if (transaction != null)
                transaction.Dispose();

            if (session != null && session.IsConnected)
                session.Close();
        }
        oLog.Debug("End");
        return projectList;
    }
4

1 回答 1

0

如果我对您的理解正确,您想从您的项目中获得不同的客户吗?

在这种情况下,我认为这样的事情应该可以工作(这应该为您提供来自此标准的 dictinct 项目 ID - 也许有一种方法可以直接获取项目 - 但我现在无法测试:

ICriteria criteria = session.CreateCriteria(typeof(Project),"Project")
                .SetProjection(Projections.Distinct(Projections.Property("project.Id")))
                .CreateAlias("Project.customer","customer",NHibernate.SqlCommand.JoinType.InnerJoin)
                .CreateAlias("Project.Coordinator", "Coordinator", NHibernate.SqlCommand.JoinType.InnerJoin)
                .Add(Restrictions.Eq("Project.ProjectType", projectType));
于 2012-10-23T13:50:14.630 回答