开发者

ICriteria subquery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜