The following resource displays how to generate Partial Class mapping for Generic repository. Our Models don't have Id column, they are always named ProductId, CustomerId, etc. (Know generic repository is under lot of debate, however manager told us to apply it)
The method results in client-side evaluation, which is slow/not allowed in EFCore 3.
Net Core: Create Generic Repository Interface Id Mapping for All Tables Auto Code Generation
public partial class Product: IEntity
{
[NotMapped]
public int Id { get => ProductId; set => ProductId= value; }
}
Does anyone have auto generated code or T4 to create this result? Would like to go through all scaffolded models and rename class member to id, and Column to CustomerId, SalesId, ProductId, etc? Code also needs to update ModelBuilder as need. Does EF Core 2 have option like this?
It can be done with Data Annotation or FluentAPI, open to any option.
public class Product
{
[Column("ProductId")]
public int Id { get; set; }
public string ProductName { get; set; }
public string ProductDescription { get; set; }
public float Cost { get; set; }
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Product>()
.Property(p => p.Id)
.HasColumnName("ProductId");
}