Generic Dal using WCF :
In this article we would learn how to create a Generic Dal with a WCF
Layer . We would use Entity Framework to create a Data Model for our
database .The Challenge is to pass the Entities to and fro using WCF
If any of you have tried doing this before you would have faced the problem of serializing and de-serializing the entities .
We would discuss about the problems when we actually face them . Lets start of creating a Generic Dal then .
In this post I would create a Dal and give some details about it .
Since This is a detailed project I have tried to break it down inorder
for better understanding .
Create a new Visual studio Project as shown below :
Have created a Class Library .
Now lets create a Data Model which we would actually use as our Data
Access Layer . We are using here the Ado.Net Entity data Model to create
the data model for our database .
So our Data Model is created . This gives a clear picture of how the tables are associated .
Entity Framework offers a tool called EntityModelCodeGenerator . While
we saw the UI being created . Behind the scenes this tool creates a very
elegant code behind for our database which maps the Data Model to the
DataContext Object is created as well . Using which
we can access all the tables in the dataModel . We could Modify the
tables i.e . Add , Update and Delete the tables and finally save the
DataContext . Saving the Datacontext would actually save the data in the
Once the DataModel is created we can take a look at what code the Entity Framework has generated for us .
This is a Abstract View of what EntityFramework does for us .
Lets check our the Contexts first . This is how the Context Object is
created . This would act as our key to accessing the DataModel and
inturn actually accessing the DataContext .
The Below screenshot shows how the Entities are created .
So Entity Framework creates partial classes for each of the tables in
the DataModel and also these classes Extend from the EntityObject
In the next post we will take a deeper look at what Entity Framework
provides us and how we can modify it to achieve a Generic Data Access