I'm working on my first .NET project (.NET 3.5, ADO.NET and C#). We've built our entity models and are trying to build a clean business objects layer.
We've got our basic entity model and we want to add certain business-level semantics to the default data accessors (navigation properties, etc).
For example, let's assume that we have a many-to-many relationship between Person
and BankAccounts
. Let's assume that at the business layer we would like to add the ability to freeze an account. We now want the ability to navigate from a Person to:
- all their bank accounts,
- their non-frozen bank accounts, and
- their frozen bank accounts.
Naturally we'd like to make the nominal case the default: If I navigate Person.BankAccounts()
I'd like it to return their non-frozen accounts. I could add the navigation properties Person.FrozenBankAccounts()
and Person.AllBankAccounts()
.
Both approaches we've come up with seem to have a fair amount of code smell.
- We can't find a way to override the entity model's methods. So, leave
Person.BankAccounts()
as the accessor that returns all bank accounts. Then we add aPerson.FrozenBankAccounts()
and aPerson.NonFrozenBankAccounts()
. - Add another explicit layer to the code base that wraps all accesses to
BankAccounts
.
With approach 1, the problem is that the nominal business case (accessing unfrozen bank accounts) is the most unintuitive method name of the lot.
With approach 2, when we subclass the objects from the entity model layer we have to override every method to ensure that it won't return objects from the underlying layer. So we create a BL_Person
which has a BankAccounts()
method that returns a collection of BL_BankAccount
objects. But in this case, all that code seems a little silly.
Is there a better approach than the two we've considered? If there isn't a better approach, which of the two I've outlined seem like the better solution (given that we've got something like 50+ classes we need to work with)?
Note: While doing a web search, I did find an open letter to Microsoft titled ADO .NET Entity Framework Vote of No Confidence that seems to imply that there isn't a good way to add in a clear separation of concerns.