0

私はこのエンティティを持っています:

MyEntityA
{
    long IDEntityA;
    List<EntityB> lstEntityB;
    .... (other properties);
}

MyEntityB
{
    long IDEntityB;
    string Name;
    .... (other properties)
}


List<long> lstIDsEntitiesB; //this list has many IDs of entities B.

プロパティ lstEntitiesB に、ID が lstIDsEntitiesB にあるエンティティが 1 つ以上あるすべてのエンティティ A を取得したいと考えています。

結合を使用する必要があるかどうか、または他の方法があるかどうかはわかりません。おそらく any または contains を使用します。

本当にありがとう。

4

1 に答える 1

1
    class MyEntityA
    {
        public long IDEntityA;
        public List<MyEntityB> lstEntityB;
    }

    class MyEntityB
    {
        public long IDEntityB;
        public string Name;
    }

    public class Test
    {
        List<long> lstIDsEntitiesB; 

        public void TestAlvaroProblem()
        {
            List<MyEntityA> entitiesA = new List<MyEntityA>();
            IEnumerable<MyEntityA> filteredOut = entitiesA.Where(a => a.lstEntityB
                            .Select(b => b.IDEntityB).Intersect(lstIDsEntitiesB).Any());
        }        
    }

lstEntityB の ID が lstIDsEntitiesB と交差する entityA を選択する必要があります

于 2014-04-10T13:47:58.133 に答える