Entities derived from generic base class

Thread is closed for posting
2 posts, 0 answers
  1. Tonny
    Tonny avatar
    10 posts
    Member since:
    Sep 2011

    Posted 24 Sep 2014 Link to this post

    I have a Data Access project that consists of entities derived from a base class, defined like this:

    public abstract class EntityBase<T> where T : EntityBase<T> { }
    public class Entity: EntityBase<Entity> { }

    ..using the horizontal inheritance strategy in Data Access, mapped like this:

    var entityBaseMapping = new MappingConfiguration<EntityBase<Entity>>();
    var entityMapping = new MappingConfiguration<Entity>();
    entityMapping.HasProperty(x => x.Id).IsIdentity();

    I did this in an attempt to consolidate a large number of entity methods (CRUD, basically) into the base class, as they were very similar, only differing in what entity they worked on or returned.

    This builds okay but fails at runtime when attempting to update the database. The call to ISchemaHandler.CreateUpdateDDLScript throws an exception :

    [InvalidOperationException: Could not execute the method because either the method itself or the containing type is not fully instantiated.]

    I'm no expert on inheritance or generics in C#, so I can't parse this. I did notice this in the stack trace, though:

    [MetadataException: Mapping for class 'Namespace.Entity' is specified in file 'config' but the class could not be found. --> Context/namespace[Namespace]/class[Entity]]

    Is my attempt at generic'izing the CRUD methods of my data layer tripping up Data Access' mapping? Is what I'm trying impossible or how do I proceed?

  2. Boris Georgiev
    Boris Georgiev avatar
    190 posts

    Posted 29 Sep 2014 Link to this post

    Hi Tonny,

    Unfortunately you bumped against limitation in Telerik Data Access. The mappings between a class with generic type and table is not supported scenario. So you should fully define all of your classes and avoid using generics in the definition.

    If any other questions arise do not hesitate to contact us again.

    Boris Georgiev
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
Back to Top