How to use attribute mapping with EF Core DB First

asp.net-core-2.0 entity-framework entity-framework-core

Question

I've generated my DbContext using Scaffold-DbContext from existing database.

It uses Fluent mapping API. Is it possible to scaffold the entities so that they are annotated with mapping attributes, e.g.:

[Table("People")]
public class Person
{
   [Column("ID")]
   public int Id {get; set;}
}
1
6
9/25/2017 8:04:29 AM

Accepted Answer

You can use Scaffold-DbContext command -DataAnnotations switch:

Use attributes to configure the model (where possible). If omitted, only the fluent API is used.

For more info, see Command Line Reference.

8
9/25/2017 8:18:42 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow