How to select Distinct Rows

Posts   
 
    
Austinn
User
Posts: 38
Joined: 25-Aug-2008
# Posted on: 10-Jul-2011 21:16:02   

Hi, I am trying to write below query in LLBLGEN.

SQL Select Distinct(CustomerNo) from Customer order by CustomerNo.

currently I am doing this

var custColl1 = custColl.Select(o => o.CustomerNo.Value).Distinct();

if this is not the proper way, please Can somebody please help me a better one.

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Jul-2011 00:35:29   

Austinn wrote:

currently I am doing this

var custColl1 = custColl.Select(o => o.CustomerNo.Value).Distinct();

What is custColl? Because seems like you are querying an EntityCollection in-memory.

If you are using LINQ2LLBL, then the code should look like this (assuming you are using Adapter templateset):

using (var adapter = new DataAccessAdapter())
{
     var metaData = new LinqMedata(adapter);
     var results = (from c in metaData.Customer
               select c.CustomerNo).Distinct().ToList();
}

You also can use DynamicLists, just pass false to the _allowDuplicates _parameter in the _FetchTypedList _method.

David Elizondo | LLBLGen Support Team
Austinn
User
Posts: 38
Joined: 25-Aug-2008
# Posted on: 11-Jul-2011 09:36:29   

Yes, I am using EntityCollection

EntityCollection<Customer> custColl = new EntityCollection<Customer>(new CustomerFactory);

Thanks, I will try.