Adding a new table to a model (edmx) without updating other models in MVC First First Entity Framework

I have an MVC 5 application that uses the Entity Framework 6 Database First approach.

So far, it works well, but I have encountered unwanted behavior.

If I select "Update Model From Database", select the "Add" tab, and then select the Tables or Views that I would like to add and click "Finish", add tables and / or views that I did not specify.

However, the undesirable behavior is that although I did not select the Refresh tab, it seems that each individual model is automatically updated.

This means that all my user attributes on my models are deleted.

Is it possible to specify only the addition of the specified tables or views without updating all models, or if it updates all models in order to preserve the attributes indicated by me?

Visual Studio Information: Microsoft Visual Studio Professional 2013 Version 12.0.40629.00 Update 5 Microsoft.NET Framework Version 4.5.51650

Installed Version: Professional

Is this a mistake or an intended use?

thanks

Nill

+4
source share
2 answers

To modify auto-generated classes, it is recommended to use a partial class, so your changes will not be lost when the class is updated / generated again.

A simple example of a class and a partial class expanding by its attributes and methods

// Assume this is autogenerated by EntityFramework
public class Book {
    public int Id {get; set;}
    public string Title {get; set;}
}

// In a different file.cs
public partial class Book {
    [Required]
    public string Author {get; set;}

    public override ToString(){
        // Some code goes here
    }
}

, EntityFramework , , , .

.

: , .

+3

, edmx .

.

+2

Source: https://habr.com/ru/post/1627409/


All Articles