views:

25

answers:

2

Hi all,

I'm finally getting around to checking out the latest EF release and I'm running into some troubles with my testing.

So, my DAL layer holds my .EDMX file and I'm using the MS POCO template so I also have the generated .TT files and classes.

I have a generic base class in the TestProject.DAL I've created that those classes derive from. I.e.

public class BaseEntity<T> {}
public class Customer : BaseEntity<Customer> {}
public class Product : BaseEntity<Product> {}

Then in my TestProject.BLL layer I have some derived classes I.e.

public class TestProject.BLL.Customer : TestProject.DAL.Customer {}
public class TestProject.BLL.Product : TestProject.DAL.Product {}

Then, in my UI layer I'm calling my BLL.Customer object. I get an error saying that the reference to the DAL.Customer object is not added, etc.

I have a reference to the BLL project from my UI project and a reference to the DAL from my BLL project.

Why is the UI layer complaining that it knows of the DAL layer when it's not referenced in that project?

Also, as a side question, does this look like a "good" design?

Thanks all! Goosey

+1  A: 

Your UI does reference the POCO entity types -- via the generic type parameter on BaseEntity.

Craig Stuntz
Thanks for the reply Craig!
Goosey
Could you elaborate on your answer a bit more? The BaseEntity is only in the DAL, which is references by the BLL which is referenced by the UI.
Goosey
I should clarify a bit more myself. I have 2 version of each entity class, 1 in the DAL and 1 in the BLL.
Goosey
+1  A: 

Craig is correct - your UI is referencing the POCO entity types. But I'll elaborate a bit more.

If you were in a situation where your UI project was referencing the BLL assembly and that assembly was referencing the DAL assembly and not publicly exposing any members from that DAL assembly, then what you are saying would be correct. But that is not what is happening here. You are referencing the BLL assembly and the types in that assembly directly inherit from the DAL types and therefore the DAL types are publicly visible to your UI. Therefore, the compiler is (correctly) telling you that you must reference the DAL assembly from your UI project.

As to your "good design" question, that always depends on context. Without knowing any of your context, I would hesitate to create an inheritance tree like this. What is the job of your sub-classes in the BLL assembly?

Steve Michelotti
So the reference is implicit based on the DLL class's visibility.
Goosey
Correct - it depends on *visibility*.
Steve Michelotti
About my design, I'm just trying to follow the basic n-Layered design pattern. I would like to keep all my domain logic in the BLL.dll i.e. Users.ChangePassword() and Users.AcceptAgreement() etc and all the DAL.dll stuff to only have the data specific items Users.Add() and lastly the BaseEntity to have related methods for all entities BaseEntity<Users>.GetById() BaseEntity<Users>.Search() etc.
Goosey