How may DataAnnotations Attributes in the DataBase First Model not be deleted?

asp.net-mvc data-annotations database-first edmx entity-framework

Question

I put up my asp.net mvc 3 application using the Database First model and entity architecture.

What I Did Below: made a database using tables. 2. Produced an.edmx file for an ADO.NET Entity Data Model and imported the tables 3. I used ADO.NET DbContext Generator to add a Code Generation item within the design. 4. A Model1.tt holder formed from all of the table models has been created.

I updated the models with DataAnnotations Attributes after editing them (just for the example a well known one)

public class LogOnModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [Display(Name = "Remember me?")]
    public bool RememberMe { get; set; }
}

Now, all the models will be rewritten and the DataAnnotations Attributes will vanish when I make changes to the database and update it to the edmx file.

How can I utilize a database first model while still being able to update the models for specific validation, like I do with a code first model? (Please don't use third-party programs as a solution)

1
10
2/25/2014 11:32:29 AM

Accepted Answer

Use buddy courses, please. http://msdn.microsoft.com/en-us/library/ee256141(v=vs.98).aspx is an old yet still relevant article I wrote.

10
2/10/2012 6:59:30 PM

Popular Answer

Put view models to use in your views.. This will separate your UI logic from your EF entities.



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