Last post Jul 02, 2010 08:28 AM by andrei.scripniciuc
Jul 01, 2010 03:18 PM|BiGBang666|LINK
I'm new to Entity Framework and while trying to catch up, it seems like I have lost the right way to learn it.
after a couple days of studying, I still have some fundamental questions regarding Entity Framework in N-Tier application.
Previously, I used to write a DB class as DAL. It had some methos to call stored procedures, using transactions, ... to return datatables from database and pass them to the BLL. in the BLL I had my custom classes (typically one class per table for non-complex
projects) and I mapped the data returned from DAL to these classes.
Now with the EF, I think the best approach for medium to large size projects would be to use the EDM as DAL in a separate project, and add a reference to it in the BLL.
1- Is my understanding of layers distinction correct?
2- This is what has been confused me a lot. How can I add custom validation? for example, I want certain users be able to modify a field (say productprice) in my website. Where should I use the User.IsInRole method? should I define partial classes in BLL
or use POCO in the BLL?
3- Are there some good code samples for EF distinct layers and validation and POCO? I think using POCO entities is what I'll end up using the most but I couldn't find some practical samples.
Any help/suggestion would be greately appreciated.
Sorry for the long message.
N - Tier
entity data model or ado.net
Jul 02, 2010 08:28 AM|andrei.scripniciuc|LINK
1. In my opinion, yes.
2. I have found it very convenient to write my own POCO entities, and write the validation logic inside them, and use exceptions where necessary. Then if you're also using a service layer just wrap the exceptions in faults and pass them to the presentation
layer. You could also consider customizing EF's code generation tool, as described in this
3. A good article describing specific elements (including validation) that you should take into consideration when using EF for building n-tier apps can be found in this
article from msdn. It also has some links at the beginning regarding more general aspects of n-tier apps.
Good luck, hope this helps.