How to Join two Entities and Get Unique Rows from One

I have 2 entities A and B, each one has a field Number, I need to get all rows from entity A where the Number does not exist in B.

Any ideas? Does it need a join?

Answers


Will that do the trick ?

  var result = entityA.Where(a => !entityB.Any(b => a.Number == b.Number))

very crude, but you can do it without a join like this

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

var result = a.Where(o => !listB.Contains(o.Number));

As you are not giving very much information it's hard to tell. But maybe you could do something like this:

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);
    }
}

Need Your Help

Control that web page could be loaded only from an specific PC

asp.net .net dll

I'm looking for just some orientation about how to control that an ASP.NET web site could be only loaded from specific IP client addresses. I mean: the user is only allowed to load web app from its...

PHP: Calculating percentage tax applied to a product

php rounding

I've got a significant problem in working out the percentage tax applied to a product, due to the rounding.