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

Fluent mapping. Inhering from other class

1 Answer 93 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dilshod
Top achievements
Rank 1
Dilshod asked on 14 May 2014, 11:17 AM
Hi,
I have mapped the database using Fluent Mapping and edited one of the generated classes. The changes I made is removing the one property and make the class inherit from other class. NOTE: base class is not in the same dll. When I run I get this error.

An unhandled exception of type 'Telerik.OpenAccess.Exceptions.MetadataException' occurred in Telerik.OpenAccess.Runtime.dll

Additional information: Mapping for field '_id' is specified in the file 'config', but the field is not present in the class 'WpfApplication2.Student'. --> EntitiesModel1/namespace[WpfApplication2]/class[Student]/field[_id]


The things I changed in the generated code.
1) Removed the Id property
2) Made the class inherit from other class which is in a different dll
3) Also tried removing KeyGenerator.Guid in Prepare[Entity]PropertyConfigurations.

Thanks,




1 Answer, 1 is accepted

Sort by
0
Boyan
Telerik team
answered on 19 May 2014, 08:27 AM
Hi Dilshod,

In order  to overcome this issue, you have to create mapping for the base class expanding your Fluent Model. For example let’s create a class named BaseEntity which has a property named Id that represents the primary key. Each entity derives from the BaseEntity class. I have created the following mapping for this class:

MappingConfiguration<BaseEntity> baseEntityConfiguration = new MappingConfiguration<BaseEntity>();
baseEntityConfiguration.MapType(x => new { }).Inheritance(InheritanceStrategy.Horizontal);
baseEntityConfiguration.HasProperty(x => x.Id).HasFieldName("_id");
mappingConfigurations.Add(baseEntityConfiguration);

Please note that there is mapping for the Id property and that the inheritance strategy is set to horizontal allowing the Id property to be part of the table that corresponds to each derived class.

In order to allow derived entities to use the Id declared in the base class the correct field (the one that comes from the base class) has to be set. For this reason the following modification in each of the derived classes mapping has to be made:

configuration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc).HasFieldName("BaseEntity._id") ...

While it is possible to distribute the model's entities in separate projects (Fluent Libraries) using the AggregateMetadataSource feature of Telerik Data Access I would advice you not to in this case unless you have some consideration that would benefit from that feature. Could you please tell us more about your current implementation scenario that requires the BaseEntitiy class to be distributed as part of another assembly so we could advice you better? Is it possible to use an interface (implemented by the BaseEntitiy class) in order to achieve the same functionality?

Please do not hesitate to contact us again should you have any further questions.


Regards,
Boyan
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Data Access Free Edition
Asked by
Dilshod
Top achievements
Rank 1
Answers by
Boyan
Telerik team
Share this question
or