Closed Burgyn closed 5 years ago
After the discussion with @satano, we propose the following convention:
public class DatabaseConfiguration: DatabaseConfigurationBase
{
public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
{
modelBuilder.Entity<Foo>()
.HasTableName("Foo")
.HasPrimaryKey(f => f.Id)
.WithName("PK_Foo")
.AutoIncrement(AutoIncrementMethodType.Custom)
.Property(f => f.FirstName).HasColumnName("Name")
.Property(f => f.LastName).NoMap()
.Property(f => f.Addresses).UseConverter<AddressConverter>()
.Property(f => f.EmailService).InjectValue(() => new EmailService());
}
}
I'm starting to work on it. You're OK with that.
Starting discussion about Use different kind of configuration than attributes from #8.
Current state
Now some configuration is allowed only using attributes (
Key
,Alias
). Something can be changed using customModelMapper
.Available attributes:
Alias
- Define name for database object (table, column).Key
- Define primary key for table.NoMap
- When property is mark with this attribute, thenKORM
ignore this column.Converter
- Define converter for converting values between database and CLR.When want use property injection, we must use
ModelMapper
:In many scenarios it's OK. However, there are scenarios where we want to have a model definition and mapping it to a database separate. For example, if you want to have entities in domain layer and mapping in infrastructure layer.
Design
The proposal is based on how it is in EF. Have a configuration class where, we are fluent define model mapping to database.
Uses in ASP.NET Core applications:
Implementation
I tried to explore it. It is possible implemented into KORM.