Should I use object class classes or model classes in controllers?

I am new to entity infrastructure and mvc.
I am trying to understand what the controller should pass into the view.
If it is a class from models (MySolution.Models.Story) or a class from an entity infrastructure (MySolution.Story).
The problem is that if I select one of the entity structures, then DataTypes and html helpers do not work correctly. If I select a class from models, then I cannot convert from an entity class to a model class, for example:

TrendEntities TrendDB = new TrendEntities();
public ActionResult Details(int id) {  
  var Country = TrendDB.Countries.FirstOrDefault(c => c.CountryId ==id);  
  return View(Country);  
}  
+3
source share
4 answers

POCO adp.net . . " " poco. " ". , - . , visual studio 2010 - POCO. :

ADO.NET # POCO Entity Generator

+2

AutoMapper ValueInjecter. "" , . AutoMapper. . ValueInjecter.

+2

, . , , MVC 3

public class StoryDBContext : DbContext
{ 
    public DbSet<Story> Stories {get; set;}
}

THAT, Entity Framework.

TrendEntities ( ) . ... , , TrendDB StoryDBContext TrendEntities, .

+2

Use ViewModel. This is the class that you declare, having the properties that you want to display in your view.

For instance:

var country = TrendDB.Countries.FirstOrDefault(c => c.CountryId == id);

CountryDetails details = new CountryDetails();
details.FirstValueToShow = country.Name;
return View(details);  

Remember to clearly indicate your view of the information in the ViewModel.

0
source

All Articles