I am pretty new to using Entity Framework. I am working on a Web MVC 2 project (for .NET 3.5) and am exploring using Entity Framework since I read that it is the recommended approach when working with data-access layer.
My question is, I have already created my database and used Visual Studio to create the Entity Models. Now, as should be, there are auto-generated classes for me to use. I've gone through some tutorials and they are using these directly.
However I am not sure. Going forward, I am thinking of needing some additional business logic to my models. So should I, as early as now, create my own Model classes?
Thank you in advance!
Best How To :
I think you meant that you have generated models through designers.It doesn't matters whether you use Code First Approach (Creating classes first) or Database First approach. Models are representation of your tables and you can access models through Dbcontext where your models are represented as DbSets.You can use dbcontext for any kind of operations on models/tables based on logic implemented.
Business logics should be not be part of models but ideally two layers far from it. Business logic layer should call data access layer(DAL) and DAL should have logic to access/manipulate data through dbContext in EF.
See Repository pattern. (https://msdn.microsoft.com/en-us/library/ff649690.aspx)
This helps Business logic to be independent of underlying data source (whether sharepoint,sql server or a web service) because DAL layer has implementation to access data.This approach also avoids code repetition and helps in data centralization and is lesser prone to errors.Adding Separation of Concern also helps in better unit testing.