This is a migrated thread and some comments may be shown as answers.

Entities derived from generic base class

1 Answer 105 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tonny
Top achievements
Rank 1
Tonny asked on 24 Sep 2014, 12:19 PM
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>>();
entityBaseMapping.MapType().Inheritance(InheritanceStrategy.Horizontal);
mappingConfigurations.Add(entityBaseMapping);
 
var entityMapping = new MappingConfiguration<Entity>();
entityMapping.MapType().ToTable("entity");
entityMapping.HasProperty(x => x.Id).IsIdentity();
mappingConfigurations.Add(entityMapping);

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?

TIA

1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 29 Sep 2014, 11:34 AM
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.

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
General Discussions
Asked by
Tonny
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or