开发者

Problem with create criteria in nhibernate

I have an entitiy as

public class Clai开发者_如何学PythonmDetail
{
   public virtual int Id { get; set; }
   public virtual Claim Claim {get;set;}
   public virtual string ServiceDateFrom { get; set; }      
   public virtual string DateCreated { get; set; }
   public virtual ClaimDetail ParentClaimDetail { get; set; }
}

I want apply left outer join on on this table as

SELECT cd.ClaimDetailId ,
cd.ParentClaimDetail_id  ,
cds.ClaimDetailId  ,
cds.ParentClaimDetail_id  ,
cds.DateCreated,
cd.DateCreated
 FROM ClaimDetail AS cd left JOIN ClaimDetail AS cds ON 
cd.ClaimDetailId = cds.ParentClaimDetail_id

I am implementing this query in nhibernate as

ICriteria query = session.CreateCriteria(typeof(ClaimDetail), "cd") 
    .CreateAlias("ParentClaimDetail", "cds", NHibernate.SqlCommand.JoinType.LeftOuterJoin);
query.SetProjection
              (
                     Projections.ProjectionList()
                       .Add(Projections.Property("cd.ParentClaimDetail.Id"), "sks")
                       .Add(Projections.Property("cd.Id"),"cdid")
                       .Add(Projections.Property("cds.DateCreated"), "dc1")
                       .Add(Projections.Property("cd.DateCreated"), "dc2")
                       .Add(Projections.Property("cds.ParentClaimDetail.Id"), "cds")
                       .Add(Projections.Property("cds.Id"),"cdsid")
              );

but this create criteria creating query as

SELECT cd.ClaimDetailId ,
cd.ParentClaimDetail_id  ,
cds.ClaimDetailId  ,
cds.ParentClaimDetail_id  ,
cds.DateCreated,
cd.DateCreated
 FROM ClaimDetail AS cd left JOIN ClaimDetail AS cds ON 
cd.ParentClaimDetail_id = cds.ClaimDetailId

can any one help me.

Thanks in advance


It looks like you want to use a named query instead. The named query goes in the mapping XML and you can feed input into it. In addition, you can select a custom class to represent the entities of the resulting data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜