Microsoft Entity Framework version 4.0 is a brand new ORM(Object Relational Mapper) from Microsoft. It’s provides now some new features which are not there in the earlier version of Entity framework. Let’s walk through a simple example of a new features which will create a new Entity class based on stored procedure result. We will use same table for this example for which they have used earlier for Linq Binding with Custom Entity.
Below is the table which have simple fields like first name,last name etc.
Let’s insert some data like following.
Below is the stored procedure which I am going to use for this example which will simply fetch data from the table.
CREATE PROCEDURE dbo.GetAllUsers
SET NOCOUNT ON
FirstName + ' ' + LastName AS [FullName]
Now click ok and now it will create function which call the stored procedure and will return Object Result set of Type ‘UserInfo’ which we have just created. Now let’s bind that to a simple grid view to see how its works. So Let’s take a simple grid view like below.
<asp:GridView ID="grdUserList" runat="server">
protected void Page_Load(object sender, EventArgs e)
using (BlogEntities myEntity = new BlogEntities())
grdUserList.DataSource = myEntity.GetAllUsers();
That’s it very easy and simple to bind complex type with stored procedure using ADO.NET Entity Framework 4.0. Hope this will help you.. Happy Programming!!!