KrisPetkov wrote:
Sorry for the dumb question( it is referenced to this specific quoted part of your post):
But what other option do we have? I mean what other choice we have to map an Enum?
And what will happen if we do not specify such an explicit mapping with the builder? Will linq2db manage to map it by it self?
Thanks and again sorry if my question is inadequate!
Regards,
Kris
At the moment, I have not found alternative for it. This is basically what we have done previously in the last version, albeit a little different.
For example, this is what I have in my 4.2 version of my plugin
public class EntityMap : NopEntityTypeConfiguration<Entity>
{
public override void Configure(EntityTypeBuilder<Entity> builder)
{
builder.ToTable("TableName");
builder.HasKey(m => m.Id);
builder.Property(m => m.PropertyName); // String property
base.Configure(builder);
}
}
And this is the equivalent in 4.3:
public class EntityMappingBuilder : NopEntityBuilder<Entity>
{
public override void MapEntity(CreateTableExpressionBuilder table)
{
table
.InSchema("TableName")
.WithColumn("Id").AsInt32().PrimaryKey()
.WithColumn(NameCompatibilityManager.GetColumnName(typeof(Entity), nameof(Entity.PropertyName))).AsString();
}
}
It is not required to have this as Nop will try automatically determine the mapping type using the FluentMigrator and linq2db based on the entity object. However, if you want to make sure your entity property types are matching the types in the database or if you want to have custom types instead, I suggest to use it.
Also, I forgot to mention one thing and that is you do not need to specify the mapping for everything. Let's say the entity contains 4 properties and 1 of that is a custom type, you can let Nop handles the other 3 and just specify told the mapping to map the one that has the custom type.
About the document, I wish I could contribute to it but kinds of busy at the moment, so that is the limit factor. Hopefully, I can do that in the near future. Also, I think Nop team could have add more specific scenarios and document since this is only my experience so far with the latest version so there could be some issues. Some of the documents are pretty barebone and when I started working with plugin development, I also struggled quite some times and I had to dig into the codebase heavily to see what is going on there.