Home > Mobile >  Entity Framework 6 - Database First - String Length Attribute missing
Entity Framework 6 - Database First - String Length Attribute missing

Time:09-24

I am using EF6 database first to create my EF 6 DB Context. The POCOs that are created are missing the property attributes such as "StringLength" or "Required". I have been on projects before where these were created for me and thought it was base functionality. Where can I find documentation on how to configure this behavior?

From a new Winform application I added a new ADO.Net Entity Data Model to my project and followed the wizard for "EF Design from database".

Environment

  • New .Net Framework 4.72 Winform app
  • EF 6
  • C#

CodePudding user response:

I found out what happened. By default Scaffold-DBContext's parameter DataAnnotations defaults to use Fluent API. Fluent API configures the properties using function chaining in the OnModelCreating method of the context. The DataAnnotations parameter is a switch, so just specifying the parameter will change the engine to use Data Annotations.

This is important to be because I use the EF Models outside of EF as well. There is a big benefit using them with ASP.net because it will use the annotations during request to validate the models.

  • Related