views:

60

answers:

1

Good people of SO,

Today I have some serious concerns on my business layer design. It is based on Entity POCO objects and I want to add logic to these entities BUT, there are 2 types of logic:

  1. Pure C# logic
  2. Persistence logic (LinqToEntities in my case)

My question is simple:

How should I separate these two kinds ?

First, I was thinking about adding these two as methods to the entities. And using partial classes to split them.

Second, I thought that I wouldn't want an overweight object with a LOT of methods. So maybe why not static classes or singleton with methods doing the LinqToEntities stuff, and leave the pure C# in entity methods. Then I would have several classes grouped by fonctionnality providing the logic, the entity is passed as argument to the classes methods.

It really bothers me, because the second solution seems cleaner but it looks like it breaks the object-oriented paradigm. On the other hand the first one seems like an anti-pattern.

What do you think ? Do you have a bright solution solving this paradox ?

Schizophrenic edit: in fact what I call persistence logic should go to the DAL and the pure c# logic in the BLL. POCO entities are produced by the DAL. I can then extend these entities in my BLL to add methods. In my DAL I should structure the logic as exposed in the second solution.

+3  A: 

The logic that describes how an entity should be saved/loaded doesn't belong to the entity itself ; it's more likely to be the role of a persistence service, a data access object, etc.

I would let the object specific logic in the object -- we're here talking about the object behavior, then create a service that handles persistence concerns for this object type.

Romain Verdier
mmmh, I am in SOA, so I don't want to create a persistence service. It would break the architecture. See, this bll will be is a service, if this service MUST rely on a persistence service, then it won't be autonomous...
Roubachof
I think you're mixing different concepts here. Consider that the service you're talking about is *one component* of your SOA architecture. It's a granularity matter : this component has it's own design. When I'm talking about a persistence service, I'm not talking about another high level independent service of your SOA ecosystem -- I'm talking about a possible inner component of your existing service. The "persistence service" can be a simple class. Read "data access object" if you prefer.
Romain Verdier
okay, the word *component* is indeed less ambiguous.
Roubachof