EntityCollectionBase2 initialContents as IEnumerable

Posts   
 
    
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 03-Feb-2009 04:16:22   

Hi,

EntityCollectionBase2.cs requires an IList in the constructor for the initialContents.. Since only AddRange is used IEnumerable would be enough and this would make it easier to pass in a query created through LINQ.

Thanks, Patrick

    /// <summary>
    /// CTor
    /// </summary>
    /// <param name="initialContents">initial contents for this collection</param>
    public EntityCollectionBase2( IList<TEntity> initialContents ) 
        : this ()
    {
        AddRange(initialContents);
    }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 03-Feb-2009 09:52:02   

This change requires a change in the templates too (as the CTor in the template has the same signature). Changing things at the same time in template and runtime is a breaking change (as people can update templates and not runtime -> error at runtime), and therefore we can't make this change now, how small it might be.

there's a different way to do this though, as I suspect you want to do this:

say you have a query like: var q = from c in metaData.Customer select c;

and you now want an EntityCollection<CustomerEntity> filled with the results. Linq's ToList returns a List<CustomerEntity> and you don't want to fill one collection with the other. Internally, the linq provider will first fetch everything into an EntityCollection<T> and return an enumerator on that collection when you enumerate 'q'. So do this: EntityCollection<CustomerEntity> customers = ((ILLBLGenProQuery)q).Execute<EntityCollection<CustomerEntity>>();

This way, the query is executed and you obtain the direct collection the data is fetched into, so no dumb migration from one collection to the other.

Frans Bouma | Lead developer LLBLGen Pro
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 03-Feb-2009 19:05:39   

Otis wrote:

we can't make this change now, how small it might be.

I understand maybe put it on the list for 2.7 or 3.0?

Thanks, Patrick

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 21-Dec-2009 11:02:27   

pat wrote:

EntityCollectionBase2.cs requires an IList in the constructor for the initialContents.. Since only AddRange is used IEnumerable would be enough and this would make it easier to pass in a query created through LINQ.

Could you please add this in v3.0 or just change the signature from IList to IEnumerable?

   /// <summary>
    /// CTor
    /// </summary>
    /// <param name="initialContents">initial contents for this collection</param>
    public EntityCollectionBase2( IEnumerable<TEntity> initialContents )
        : this ()
    {
        AddRange(initialContents);
    }

Otis wrote:

So do this: EntityCollection<CustomerEntity> customers = ((ILLBLGenProQuery)q).Execute<EntityCollection<CustomerEntity>>(); This way, the query is executed and you obtain the direct collection the data is fetched into, so no dumb migration from one collection to the other.

This is only works on fetches not when I want to create a EntityCollection from Entities in memory before a save.

Thanks, Patrick

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 17-Feb-2010 03:55:15