This question is locked. New answers and comments are not allowed.
Hello there:
I'm trying to implement inheritance with multiple fluent metadata source, using one fluent metadata source as a base for another fluent metadata. I'll put some samples to illustrate my idea.
This code is for the base clases:
And this is for the final classes:
Well, the class library compiles without errors, but, when I create the database structure, only the tables for the base classes are mapped with the dessired relations to each other, and the table for the Application entity is mapped like if there is no inheritance on it, ad only the fields on the Application class are created the other fields of the base classes are ignored.
This image show the generated database tables for this example.
OpenAccess Database Example
I want the Application table to be created with a relation to the AuditEnableEntity, like the AuditEnableEntity table has a relation to the AuditEntity table.
How can I do that using multiple fluent metadata sources? I need to do that for a project that will have a base tables and extent the data base with aditional tables using the base classes.
I hope that I explained well and that you understand my question.
Thanks for your help in advance.
Abimael Ordonez.
I'm trying to implement inheritance with multiple fluent metadata source, using one fluent metadata source as a base for another fluent metadata. I'll put some samples to illustrate my idea.
This code is for the base clases:
public abstract class BaseEntity{ public Int32 Id { get; set; }}public abstract class AuditEntity : BaseEntity{ public Int32 CreatedByUserId { get; set; } public DateTime CreatedOnDate { get; set; } public Int32 LastModifiedByUserId { get; set; } public DateTime LastModifiedOnDate { get; set; }}public abstract class EnableEntity : BaseEntity{ public Boolean Enabled { get; set; }}public abstract class AuditEnableEntity : AuditEntity{ public Boolean Enabled { get; set; }}public class BaseEntitiesMetadataSource : FluentMetadataSource{ public BaseEntitiesMetadataSource() : base() { } public BaseEntitiesMetadataSource(AggregationOptions aggregationOptions) : base(aggregationOptions) { } public BaseEntitiesMetadataSource(MetadataContainer metadataContainer) : base(metadataContainer) { } public BaseEntitiesMetadataSource(MetadataContainer metadataContainer, AggregationOptions aggregationOptions) : base(metadataContainer, aggregationOptions) { } protected override IList<MappingConfiguration> PrepareMapping() { IList<MappingConfiguration> res = new List<MappingConfiguration>(); MappingConfiguration<BaseEntity> bec = new MappingConfiguration<BaseEntity>(); bec.MapType().Inheritance(InheritanceStrategy.Vertical).ToTable("BaseEntity"); bec.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc); bec.FieldNamingRules.AddPrefix = "_"; MappingConfiguration<AuditEntity> baec = new MappingConfiguration<AuditEntity>(); baec.MapType().Inheritance(InheritanceStrategy.Vertical).ToTable("AuditEntity"); baec.FieldNamingRules.AddPrefix = "_"; MappingConfiguration<EnableEntity> beec = new MappingConfiguration<EnableEntity>(); beec.MapType().Inheritance(InheritanceStrategy.Vertical).ToTable("EnableEntity"); beec.FieldNamingRules.AddPrefix = "_"; MappingConfiguration<AuditEnableEntity> baeec = new MappingConfiguration<AuditEnableEntity>(); baeec.MapType().Inheritance(InheritanceStrategy.Vertical).ToTable("AuditEnableEntity"); baeec.FieldNamingRules.AddPrefix = "_"; res.Add(bec); res.Add(baec); res.Add(beec); res.Add(baeec); return res; }}And this is for the final classes:
public class Application : AuditEnableEntity{ public Guid Guid { get; set; } public String Name { get; set; } public String Description { get; set; }}public class EntitiesMetadataSource : BaseEntitiesMetadataSource{ public EntitiesMetadataSource() : base() { } public EntitiesMetadataSource(AggregationOptions aggregationOptions) : base(aggregationOptions) { } public EntitiesMetadataSource(MetadataContainer metadataContainer) : base(metadataContainer) { } public EntitiesMetadataSource(MetadataContainer metadataContainer, AggregationOptions aggregationOptions) : base(metadataContainer, aggregationOptions) { } protected override IList<MappingConfiguration> PrepareMapping() { IList<MappingConfiguration> res = new List<MappingConfiguration>(); MappingConfiguration<Application> ac = new MappingConfiguration<Application>(); ac.MapType().Inheritance(InheritanceStrategy.Vertical).ToTable("Application"); ac.FieldNamingRules.AddPrefix = "_"; res.Add(ac); return res; }}public class MangauAppsContext : OpenAccessContext{ private static string connectionStringName = "MangauAppsTest"; private static BackendConfiguration backend = GetBackendConfiguration(); private static MetadataSource metadataSource = new AggregateMetadataSource(new BaseEntitiesMetadataSource(), new EntitiesMetadataSource(), AggregationOptions.Immediate); public MangauAppsContext() :base(connectionStringName, backend, metadataSource) { } public MangauAppsContext(string connection) :base(connection, backend, metadataSource) { } public MangauAppsContext(BackendConfiguration backendConfiguration) :base(connectionStringName, backendConfiguration, metadataSource) { } public MangauAppsContext(string connection, BackendConfiguration backendConfiguration) :base(connection, backendConfiguration, metadataSource) { } public IQueryable<Application> Applications { get { return this.GetAll<Application>(); } } public static BackendConfiguration GetBackendConfiguration() { BackendConfiguration backend = new BackendConfiguration(); backend.Backend = "mssql"; return backend; }}Well, the class library compiles without errors, but, when I create the database structure, only the tables for the base classes are mapped with the dessired relations to each other, and the table for the Application entity is mapped like if there is no inheritance on it, ad only the fields on the Application class are created the other fields of the base classes are ignored.
This image show the generated database tables for this example.
OpenAccess Database Example
I want the Application table to be created with a relation to the AuditEnableEntity, like the AuditEnableEntity table has a relation to the AuditEntity table.
How can I do that using multiple fluent metadata sources? I need to do that for a project that will have a base tables and extent the data base with aditional tables using the base classes.
I hope that I explained well and that you understand my question.
Thanks for your help in advance.
Abimael Ordonez.