2016-11-11 2 views
0

EFクエリをNHibernateに変換すると、JoinAliasを使用する行の数が少なくなるという問題が発生しました。以下はNHibernate JoinAliasを使用してEntity Frameworkと比較して少ない行を返しました

//Something like this cannot be used in NHibernate 
x.UserEntity.type_id == typeId1 

NHibernateのクエリに変更する必要があるかについての両方のクエリ

//Entity Framework 
dbContext.Seeker.AsNoTracking() 
    .Where(x => x.posting_id == postingId 
      && (x.source_id == sourceId1 || x.source_id == sourceId2) 
      && x.status_id != statusId1 && 
       (x.status_id == statusId2 || x.status_id == statusId3 || 
       x.status_id == statusId4 || x.status_id == statusId5 || 
       x.status_id == statusId6 || x.status_id == statusId7 || 
       x.status_id == statusId8 || x.status_id == statusId9) 
      && (x.UserEntity.type_id == typeId1 || x.UserEntity.type_id == typeId2) 
      && (x.rating == rating1 
       || (x.rating >= rating2 && x.rating < rating3) 
       || (x.rating >= rating4 && x.rating < rating5) 
       || (x.rating >= rating6 && x.rating < rating7) 
       || (x.rating >= rating8 && x.rating < rating9) 
       || x.rating == rating10)); 

//NHibernate 
(db.QueryOver<Seeker>() 
    .Where(x => x.posting_id == postingId 
    && (x.source_id == sourceId1 || x.source_id == sourceId2) 
    && x.status_id != statusId1 && 
       (x.status_id == statusId2 || x.status_id == statusId3 || 
       x.status_id == statusId4 || x.status_id == statusId5 || 
       x.status_id == statusId6 || x.status_id == statusId7 || 
       x.status_id == statusId8 || x.status_id == statusId9) 
    && (x.rating == rating1 
     || (x.rating >= rating2 && x.rating < rating3) 
     || (x.rating >= rating4 && x.rating < rating5) 
     || (x.rating >= rating6 && x.rating < rating7) 
     || (x.rating >= rating8 && x.rating < rating9) 
     || x.rating == rating10)) 
    .JoinAlias(ue => ue.UserEntity,() => u).Where(() => u.type_id == typeId1 || u.type_id == typeId2)); 

任意の手がかりがありますか?

+0

各クエリで生成されたSQLを比較しましたか?これは、両者の違いを特定するのに役立ちます。 –

答えて

1

「QueryOver」ではなく「Query」を参照してください。クエリは、標準のLinqからほとんどすべてをサポートしています。

関連する問題