Question

I have the following n-tier design.

In descending order of what can see what:

View> ViewModel> Business Logic Layer> Data Acess Layer(repositories)

Currently, the view model uses a business object to do some high level action(add something to the database) and the BLL uses the DAL to do the low level operations. The DAL only has simple atomic operations(CRUD operations), whereas the BLL uses a Unit of work pattern to accomplish a higher level business operation that may require access to different repositories, etc. So the business logic for doing these operations exists in the BLL.

My issue is that right now I am having an issue thinking about what my models would be. Since I am using entity framework, my business models are basically my EF entities. I have been told by everyone that the business logic should go in the model. If that is true, what is the point of the business logic layer if each model contains individual business logic? I feel like I would have 2 areas where I have "business logic".

And how would I add business logic to my EF entities, since I am not using code-first and the entities get re-created when I change my .edmx.

Thank you.

Was it helpful?

Solution

To answer your second question, EF classes are marked as "partial" which means you can create a new file (in the same assembly), put another "partial" class with the same name as the generated class in it and the compiler will act as if the code in your new file is present in the generated code.

The first question is more complicated, I would put the business logic where it makes the most sense. If it pertains to a specific entity, make it part of the partial class mentioned above. If it would have to interact with multiple entities, deal with other sources, etc, it should probably go in its own class. Duplicating code is almost never the right answer.

Note that in my opinion, the "Model" is the underlying business logic and data in MVVM. It doesn't necessarily mean that it is just in the data objects, or all in one object. It is simply separated from the View and ViewModel objects.

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