fetch arraylist of Ids without fetching entities

Posts   
 
    
p3mek
User
Posts: 68
Joined: 19-Feb-2007
# Posted on: 15-Jun-2013 15:36:39   

Hi

In a situation where a [User] can have multiple [Accounts]

Apart from fetching all the entities by User.Accounts is there a method for fetching only an arraylist of [Account].[Id] for a particular user without actually fetching the collection?

I looked into projections but can't find a suitable example.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Jun-2013 06:07:37   

You can use DynamicLists. Something like this:

var fields = new EntityFields2(1);
fields.DefineField(AccountFields.Id, 0);

var results = new DataTable();
using (var adapter = new DataAccessAdapter())
{
    adapter.FetchTypedList(fields, results, null);
}

... or the Linq2LLBL version:

var metaData = new LinqMetaData(adapter);
var q = from a in metaData.Account
            select a.Id;
David Elizondo | LLBLGen Support Team