Join or IN () ?

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 29-Jul-2008 20:07:56   

I have a class EntityCollection<CustomerEntity> in memory.

I want to see if any of these CustomerEntites are in the Database already. (Based on = "CustomerName")

The EntityCollection<CustomerEntity> is filled via a user entering data, it has never see a database.

I want to know if these Customers are already in the System using the LinqMetaData class.

Can I join or do an IN() ? (all in LINQ)

Ideas?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Jul-2008 05:33:28   

Hi ianvink, what about this way?

// given an EntityCollection<CustomersEntity> customersINMemory filled with in-memory values

string[] names = (from c in customersINMemory
        select c.CustomerName ).ToArray();

using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    LinqMetaData metaData = new LinqMetaData(adapter);

    var q = from c in metaData.Customer
            where names.Contains(c.CustomerId)
            select c;

    ...
}
David Elizondo | LLBLGen Support Team
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 30-Jul-2008 14:49:54   

The legendary LLBL support team saves the day again.