0

我有 2 个实体AB每个实体都有一个字段Number,我需要从不存在的实体A中获取所有行。NumberB

有任何想法吗?需要加盟吗?

4

3 回答 3

3

这会奏效吗?

  var result = entityA.Where(a => !entityB.Any(b => a.Number == b.Number))
于 2012-06-11T11:49:42.167 回答
0

非常粗糙,但你可以在没有这样的连接的情况下做到这一点

var listB = b.Select(o => o.Number).Distinct();

var result = a.Where(o => !listB.Contains(o.Number));
于 2012-06-11T11:50:28.947 回答
0

由于您没有提供太多信息,因此很难说。但也许你可以做这样的事情:

public class TestEntity
{
    public int Number { get; set; }
    public TestEntity(int num)
    {
        Number = num;
    }
}

public void WriteResult()
{
    List<TestEntity> lstA = new List<TestEntity>();
    List<TestEntity> lstB = new List<TestEntity>();
    for (int i = 0; i < 10; i++)
    {
         lstA.Add(new TestEntity(i));
         lstB.Add(new TestEntity(i+4));
    }

    List<TestEntity> result = lstA.FindAll(teA => !lstB.Any(teB => teA.Number == teB.Number)); //This will give you all entities in lstA that does not have any equals in lstB
    foreach (var item in result)
    {
         Console.WriteLine(item.Number);
    }
}
于 2012-06-11T11:51:43.327 回答