0

Employee: BaseEntityクラスを持っています

public virtual BaseEntity Department {get;set;}
public virtual BaseEntity Position {get;set;}

およびBaseEntityクラス:

public virtual long Id {get;set;}
public virtual long Name {get;set;}

このようにエンティティをマップして /create select を作成するにはどうすればよいですか

SELECT  DepartmentTable.nvarchar1 as Department, PositionTable.nvarchar1 as Position,    COUNT(*) as N      
FROM AllUserData EmployeeTable 
    left outer join AllUserData PositionTable on EmployeeTable.int2=PositionTable.tp_ID 
    left outer join AllUserData DepartmentTable on  EmployeeTable.int3=DepartmentTable.tp_ID         
 WHERE  EmployeeTable.tp_ListId = @p0 and PositionTable.tp_ListId = @p2 and DepartmentTable.tp_ListId = @p1
GROUP BY DepartmentTable.nvarchar1, PositionTable.nvarchar1;

私はこのように試しました:

var criteria = session.CreateCriteria<Entities.Employee>();
criteria.CreateAlias("Position", "PositionTable", JoinType.LeftOuterJoin);
criteria.Add(Restrictions.Or(Restrictions.Eq("PositionTable.ListId", Program.PositionListGuid), Restrictions.IsNull("PositionTable.Id")));

criteria.CreateAlias("Department", "DepartmentTable", JoinType.LeftOuterJoin);
criteria.Add(Restrictions.Or(Restrictions.Eq("DepartmentTable.ListId", Program.DepartmentListGuid), Restrictions.IsNull("DepartmentTable.Id")));

criteria.Add(Restrictions.Eq("ListId", Program.EmployeeListGuid));
var projectionList = Projections.ProjectionList();
projectionList.Add(Projections.RowCount());
projectionList.Add(Projections.GroupProperty("Department"), "AliasedId");
criteria.SetProjection(projectionList);
criteria.SetResultTransformer(Transformers.AliasToBean(typeof(BaseEntity)));
var list = criteria.List<BaseEntity>();
// "More than one row with the given identifier was found" exception raised here

私は混乱しています.Projections.GroupPropertyに結合テーブルエイリアスを使用する必要がありますか?

4

1 に答える 1