Using the first database approach in the Entity Framework

I am new to MVC and new to using EF. In our application, we use the first approach to the database. Since we use the first DB approach, we separate edmx from db.

When I create edmx, it generates all the related classes for tables in my database. Here I am only confused whether to use the generated classes in my views directly or whether I need to create another class of classes on top of the generated EF class and use them from my controllers and views.

If I create another class of classes on top of entities, I must take care of matching these classes in betweeb. I doubt this could be a pain in the future if there are any changes to the model.

If I directly use entities from my controllers, I feel like I'm exposing all unnecessary things to controllers and views.

Can someone please advise me how to do this?

+5
source share
2 answers

You do it well, as you have, you do not need to change it. You should be able to use the generated classes, or if you think you are exposing too much, you can create a presentation model in which you will fill in only the data that you need and pass it to the view. This is how MVC should work.

, Articles, , , ,

public class ArticlesViewModel
{
    [Required] // this is optional, just to give you an idea of validation
    public string Title { get; set; }
    public DataTime Date { get; set; }
}

- :

ArticlesViewModel articleVM = new ArticlesViewModel();
// populate it from your DB

return View(articleVM);

, Title Date ( ID, Article .)

, .

+3

, NuGet POCO (Plain Old # Objects - , , EF), "" "", EF .

" " " " - , , DAL , , .

EF , EF - POCOs .

:

Entity Framework 4/POCO - ?

+2

All Articles