Tips while working with Entity Framework

I started to work with ADO.NET Entity Framework last week evaluating it from my future projects. While working on it I came up with couple of hurdles but all these were short comings in the version 1.0. It’s expected that it is all going to be fixed by 4.0 (.NET 4.0 Version release). Some of the learning’s  I wanted to illustrate are as follows

 

1. Use of Stored Procedures

                When we use Stored Procedures and want to map this to any entity. Assume that we have created a SP for inserting data into a table. After we do a function import of the SP. When we do a function mapping of SP there are three options as shown below

 

 

 

But we may have only the Insert Stored Procedure and there is no need for Update and Delete. In this case we cannot use this function mapping because as per Ver 1.0, all the three is a must. The workaround for this is to create a Connection and Call the SP using the EntityConnection and EntityCommand  . To build the Connection String have a look at this http://msdn.microsoft.com/en-us/library/bb738533.aspx . Implement this like how we access a stored procedure using SQL Connection and SQL Command Objects.

 

2. Custom Results Mapping

                If we have a Stored Procedure which returns custom results having columns from multiple columns or having calculated fields. Then we can create custom entities with the fields that is resulting from the SP's. When this SP is called the returning data can be assigned to the custom entity.

 

3. Handling Scalar Return Type 

                If your Stored Procedures are returning only a Int or String or any Scalar Type, we can use the EntityConnection and EntityCommand as explained in point 1 above and we can work with the returned scalar type.

 

Hope these would be helpful for those who are planning to work with Entity Framework.

 

More to follow soon..

 

Cheers!!!

 

Comments

Popular posts from this blog

Jesus - God Thinks of you.

Derived Tables