2 Replies - 4210 Views - Last Post: 23 January 2012 - 04:32 PM

#1 webwired  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 339
  • Joined: 26-August 07

Creating new Models in MVC3 project w/Entity Framework

Posted 13 January 2012 - 09:19 AM

Hello everyone... So I'm beginning my journey of creating my first MVC3 project... The one thing that I'm a bit hung up on though is, once you add an Entity Framework Model, it of course creates the .edmx file in the Models directory, but what about the Model Class files to put all of the server side validation and business rules?

Do I need to just add regular Class files to the Models directory... and if so, should I create like a different Class file for each grouping of tables, eg., Profiles and then all the one-to-many tables that go with it --> all in one Class file?

Or should I create just 1 Class file in the Models directory that covers all of the tables in the Entity Framework Model? But that doesn't quite seem right, since included in the project is a separate Account Model... I'm not sure how many tables are involved with the built-in Account Model, but if it's just one then that would seem like you should have a separate Model for each table in the Entity Framework Model...

Is This A Good Question/Topic? 0
  • +

Replies To: Creating new Models in MVC3 project w/Entity Framework

#2 webwired  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 339
  • Joined: 26-August 07

Re: Creating new Models in MVC3 project w/Entity Framework

Posted 14 January 2012 - 09:40 AM

Nevermind, figured it for myself.
Was This Post Helpful? 0
  • +
  • -

#3 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Creating new Models in MVC3 project w/Entity Framework

Posted 23 January 2012 - 04:32 PM

You can create a partial class for each Model you want to create.

public partial class Product
{
    [Required(Error="You have to type in a product name.")]
    public string Name { get; set; }
}


But I advise against this, instead keep your EF generated classes separate in a Domain project (a class library) and create your view models as needed. Don't mix em up!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1