new EntityCollection<T>();

Posts   
 
    
jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 21-Jul-2011 14:14:51   

Hi there,

I'm trying to use the DataAccessAdapter.FetchEntityCollection() using a Generic EntityCollection. Therefore i try to create a new EntityCollection<T>(). While constructing the collection i get the follwing error: "No parameterless constructor defined for this object."

// HelperClasses\EntityCollection.cs Line: 71 // Line 69: { Line 70: /// <summary>CTor which determines the factory to use from the generic type argument, unless TEntity is an abstract entity. If possible use the ctor which accepts a factory</summary> Line 71: public EntityCollection() : base( (IEntityFactory2)null ) Line 72: { Line 73: }

It seems there is a Parameterless Constructor....

My code:

public class LlblGenRepository<TEntity> : IRepository<TEntity> where TEntity : EntityBase2, IEntity2, ITenantEntity {

    /// <summary>
    /// Return the fetched list of entities
    /// </summary>
    /// <returns>The fetched list of entities</returns>
    /// 
    public IQueryable<TEntity> List()
    {

        // Prepare the list
        EntityCollection<TEntity> list = new EntityCollection<TEntity>();
        ...

        // Fetch the collection
        adapter.FetchEntityCollection(list, null);

        // Return the list of entities 
        return (IQueryable<TEntity>)list;
    }

}

**Stack Trace: ** [MissingMethodException: No parameterless constructor defined for this object.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241 System.Activator.CreateInstance(Type type, Boolean nonPublic) +69 SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase21.DetermineEntityFactory() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\EntityCollectionBase2.cs:1499 SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase21..ctor(IEntityFactory2 entityFactoryToUse) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\EntityCollectionBase2.cs:116 X.Y.Data.HelperClasses.EntityCollection`1..ctor() in c:\Myprojects\VS.NET Projects\DatabaseGeneric\HelperClasses\EntityCollection.cs:71 X.Y.Business.Logic.PartyManager.ListCustomers() in c:\Myprojects\VS.NET Projects\X.Y.Business.Logic\PartyManager.cs:136 ...

What's it i'm doing wrong? or isn't it possible to construct a Generic EntityCollection?

Version: 3.1 Final

Regards, J

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 21-Jul-2011 18:49:17   

It's perfectly possible, and indeed your code compiles and runs fine on my machine - so something odd is going on...

Please can you ensure that you have a clean build (generate the code to a new folder) and make sure that you are referencing all of the correct versions of the runtimes etc.

If that doesn't resolve things come back to us and we'll investigate further.

Thanks

Matt

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Jul-2011 06:42:53   

It runs over here too. I needed to call .AsQueryable in the repository though.

public class GenericFetchRepositoryTests
{
[TestMethod]
public void FetchCustomerFromRepository()
{
    LlblGenRepository<CustomerEntity> customerRepository = new LlblGenRepository<CustomerEntity>();
    var customers = customerRepository.List();

    Assert.AreEqual(91, customers.Count());
}


public class LlblGenRepository<TEntity> where TEntity : EntityBase2, IEntity2
{
/// <summary>
/// Return the fetched list of entities
/// </summary>
/// <returns>The fetched list of entities</returns>
/// 
public IQueryable<TEntity> List()
{                       
    // Prepare the list
    EntityCollection<TEntity> list = new EntityCollection<TEntity>();
    DataAccessAdapter adapter = new DataAccessAdapter();

    // Fetch the collection
    adapter.FetchEntityCollection(list, null);
            
    // Return the list of entities

    return (IQueryable<TEntity>)list.AsQueryable();
}

(Edit) Is the entity abstract? (the entity you are trying to fetch through this repository). If so, you need to pass the factory to the constructor I'm afraid.

David Elizondo | LLBLGen Support Team
jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 22-Jul-2011 10:59:10   

Thank you guy's for your responses.

It had to do with abstract entities... I was fetching a list of Relations (which is abstract) and from there i wanted to fetch the subtypes Contact and Organization.

My solution was to do 2 queries ( 1 for all contacts, and 1 for all organizations) and union them to create a list or relations. I'm not sure which impact this will have on the performance, but that's something to find out later.

Thanks again! J.