开发者

ICriteria subquery

开发者 https://www.devze.com 2023-03-01 10:19 出处:网络
I have to simple entities public class EntityA { public virtual int ID { get;set;} public virtual string Name { get;set;}

I have to simple entities

    public class EntityA
    {
         public virtual int ID { get;set;}
         public virtual string Name { get;set;}
         public virtual IList<EntityB> BList { get;set;}

         public EntityA()
         {
            BLIst = new List<EntityB>();
         }
    }


    public class Enti开发者_如何学GotyB
    {
         public virtual int ID { get;set;}
         public virtual string Name { get;set;}
         public virtual int Value { get;set;}
         public virtual EntityA EntityA { get;set;}
    }

How do i make a ICriteria Query where EntityA.Name = 'SearchString' and List should be queried (((EntityB.Name='Name1' And (EntityB.Value=1)) And ((EntityB.Name='Name2') And (EntityB.Value=1)))

The search can contain a List and i tried the following query:

            if (SearchBLIst.Count > 0)
            {
                foreach (EntityB searchAttribute in SearchBLIst)
                {
                    Junction disjunction1 = Restrictions.Disjunction();
                    disjunction1.Add(
                                Expression.Eq("entityB.ID", searchAttribute.ID) &&
                                Expression.Ge("attributeValues.Value",searchAttribute.value));
                    store.Add(disjunction1);

                }
            }


Entity b name is expected to be 2 different values at the same time.

I'm guessing you want to use the other entity's property in the restriction too. You need "join alias".

0

精彩评论

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