Question

I'm using the ADO.NET Entity Framework as the data access layer in my application, but I'm not sure where I should be putting business logic. Are there any best practices or samples available that illustrate how to integrate business logic with Entity Framework entities?

After Edit:
I want any samples with implement calculation,security,rules and other things in BLL ... Any article and samples..!

Was it helpful?

Solution

You can use entities as business objects. Implement Business Logic msdn library article explain how do it. If you follow the link you will found code samples to fit business logic during Property Changes and when Saving Changes.

Remember that you can extend EF with partial classes with custom business logic.:

"The ADO.NET Entity Framework includes a tool that, given an EDM schema, will generate the .NET classes that represent the EDM entities inside the .NET environment. The generated classes are partial classes, so they can be extended with custom business logic in separate files without interfering with the code generator."

Customizing Objects msdn article also covers this topic.

On n-tier solutions for Rich Internet Applications (RIA) you can add Business Logic to the Domain Service

OTHER TIPS

You should have a Business Layer (either a separate project that references your Data Access Layer or at least some sort of directory where your business objects reside). These business objects should be the ones talking to your DAL directly. In other words, don't implement business logic on your DAL since it doesn't belong there.

I'm sure you have seen this diagram before:

enter image description here

I wouldn't put your business logic/rules in the Entity Framework - it serves as a data access layer. I would create a seperate business logic project (class library) this can call your data access layer to get/set data and enforce business rules along the way, this way you can reuse the rules should your data access layer change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top