Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

I am Jalpesh Vadgama a Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 6 years of experience in .NET Technology.
Browse by Tags · View All
#ASP.NET 88
#DOTNET 87
BRH 79
ASP.NET 72
#.NET 52
C#.NET 48
DOTNET 44
ASP.NET 4.0 31
ASP.NET MVC 29
VisualStudio 27

Archive · View All
December 2010 16
July 2011 13
April 2011 13
April 2012 12
January 2011 12
June 2011 11
May 2011 11
May 2012 8
February 2013 7
January 2013 7

Binding A Custom Entity Class to stored procedure using Linq-To-SQL

Aug 3 2010 2:44AM by Jalpesh   

I have already written several post about Linq its a great ORM that we can use in various way. The purpose of this post to demonstrate How we can bind custom entity to stored procedure result with use of Linq-To-SQL. Let’s go through it and you will realize that how easy it will be to bind a Custom Entity to Stored Procedure result.

Let’s first create a simple table to which will hold the user data. It will contain four field like UserId,UserName,FirstName and LastName like following.

SQLTable

Now let’s insert some data into the table like following.

SQLTableData

Now let’s create a stored procedure which will return the table data and a new field called Full Name like following. Here full name is a combination of first name and last name 

CREATE PROCEDURE dbo.GetAllUsers
	
AS
	SET NOCOUNT ON
	SELECT 
		UserId,
		UserName,
		FirstName,
		LastName,
		FirstName + ' ' + LastName AS [FullName]

	FROM dbo.Users

After creating a stored procedure it time to create a Linq-To-SQL Right Click Project->Add New Item and Go To->Data and Add LINQ to SQL Classes called MyBlogDataContext.dbml.

After creating datacontext class for Linq just drag above store procedure to Linq-To-SQL classes and it will create a function like following.

StoredProcedureInLinqClass

Now let’s add a New Entity Class called UserInfo into Linq-To-SQL DataContext via Right Click Add New Class Just like following.

AddClass

After adding class I have added same property as its having in user table and Hence our UserInfo Class will look like following.

UserInfoClass

Now everything is ready Custom Entity Class called UserInfo and we have Our Function ready which will return Stored Procedure output. Here Linq-To-SQL Provides a property called ReturnType If you select function which we have created via dragging a stored procedure in data context class. We just need to select our UserInfo class there just like following and it will bind the stored procedure with that particular UserInfo class. here only condition should be satisfied that Our Custom Entity class should contain all the field with compatible .NET Data types which will return the data. Below is the property which we are talking about.

SelectProperty

Now let’s add grid view to default.aspx page like following and Let’s bind output of stored procedure to that grid view.

<asp:GridView ID="grdUserList" runat="server">
</asp:GridView> 

After placing the Grid View in page here is the code for biding grid view in default.aspx page_load event.

protected void Page_Load(object sender, EventArgs e)
{
   if (!Page.IsPostBack)
   {
     using (MyBlogDataContextDataContext myContext =
					 new MyBlogDataContextDataContext())
     {
          List<UserInfo> MyUserList = 
				myContext.GetAllUsers().ToList<UserInfo>();
          grdUserList.DataSource = MyUserList;
          grdUserList.DataBind();  
      }
   }
}

And here is the output which we get in browser after running our web application.

Ouput

That’s it its very easy.. Hope this will help you…

Shout it

Tags: SQLServer, SQLConnection, Linq-To-SQL, C#.NET, Entity, BRH, #DATAACCESS, #DOTNET, #LINQ, LINQ,


Jalpesh
15 · 11% · 3478
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]