Friday, December 9, 2011

WCF Enitity reference problem for data access bussiness and entity dll by known type

Hi,
Started writting back after all most 3 years. now i am again back in the bussiness of programming.

This time i am really sharing you my unique experience in wcf.
In one of our project we need to create the following layers as there are in most of the system .

UI
Bussiness
Service Layer A (residing of different server)
Service Layer B (residing on different server)
Data Access Layer

so to keep the enitites common in all this layer we created a project named Enitit Library so the problem arrised when we reffer service in the bussines. It started to create the classes of the Same name with different name space in the bussiness layer.
So when sending entities from bussiness to UI or Bussiness to service i need to do conversion of the smae entites in different ways. At that time the Known type attribute really saved me.

[DataContract]
[Serializable]
[KnownType(typeof(Project.Entity.MyClass))]
public class MyClass
{
data members....
}

this little thing just saved my life, it stopped creating classes in bussiness layer when i referenced the service to bussiness layer.