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...
2 Replies - 3718 Views - Last Post: 23 January 2012 - 04:32 PM
#1
Creating new Models in MVC3 project w/Entity Framework
Posted 13 January 2012 - 09:19 AM
Replies To: Creating new Models in MVC3 project w/Entity Framework
#2
Re: Creating new Models in MVC3 project w/Entity Framework
Posted 14 January 2012 - 09:40 AM
Nevermind, figured it for myself.
#3
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.
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!
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!
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote



|