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开发者_如何学C 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
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?
Your UI does reference the POCO entity types -- via the generic type parameter on BaseEntity
.
精彩评论