question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Generate IEntityTypeConfiguration<T> Mappers

See original GitHub issue

Currently all the mapping of the EntityTypes are generated in the function: protected override void OnModelCreating(ModelBuilder modelBuilder). This can become pretty large… I suggest we create scaffold a IEntityTypeConfiguration file for each entity and use these in the OnModelCreating function.

For example: Customer.cs

CustomerConfiguration.cs

internal class CustomerConfiguration : IEntityTypeConfiguration<Customer>
{
  public void Configure(EntityTypeBuilder<Customer> builder)
  {
     builder.HasKey(c => c.AlternateKey);
     builder.Property(c => c.Name).HasMaxLength(200);
     // ...
   }
}

DbContext

// OnModelCreating
builder.ApplyConfiguration(new CustomerConfiguration());

Optional:

  • Choose a template name suffix

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
ErikEJcommented, Mar 13, 2019

The project is open source and accepts PRs

2reactions
ErikEJcommented, Feb 28, 2020

Will implement using https://github.com/lauxjpn/DbContextOnModelCreatingSplitter - initially just a checkbox to enable this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating and Configuring a Model - EF Core
This model is built using a set of conventions - heuristics that look for common patterns. The model can then be customized using...
Read more >
EF Core Mapping EntityTypeConfiguration
Try the new dependency injection tools? Make an IEntityMapperStrategy interface with a void MapEntity(ModelBuilder, Type) signature and bool ...
Read more >
A Cleaner Way To Do Entity Configuration With EF Core
It works like this. Create a class called {EntityName}Configuration and inherit from IEntityTypeConfiguration<Entity>. public ...
Read more >
Customizing EF Core 2.0+ Entity/Table Mapping with ...
Let's say you want to make a customization to one of your EF Core 2.0 properties and how it maps to your underlying...
Read more >
Implementing Missing Features in Entity Framework Core
My implementation finds mapping classes in the same assembly as the context ... public interface IEntityTypeConfiguration<T> where T : class
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found