SIGN UP MEMBER LOGIN:    
ARTICLE

How to Use a Custom Entity Class to Stored Procedure Using Linq-To-SQL

Posted by Raj Kumar Articles | LINQ with C# May 08, 2011
This article demonstrates how to use a Customer Entity Class to stored procedure using Linq-To-SQL.
Reader Level:
Download Files:
 


This article demonstrates how to use a Customer Entity Class to stored procedure using Linq-To-SQL.

Getting Started:

  1. Create a new website in asp.net
  2. Put website name and browse save location
  3. Click OK.

Create a new database and make a new table and add some columns.

img1.jpg

Figure 1.

Insert some data in table.

img2.jpg

Figure 2.

Create a new stored procedure and select records to show on page.

img3.jpg

Figure 3.

Add a new Linq to SQL Classes in application.

img4.jpg

Figure 4.

If a data connection is not added then add a new data connection in the Server Explorer.

img5.jpg

Figure 5.

Configure a data connection with server name, authentication and database.

img6.jpg

Figure 6.

Now drag and drop a stored procedure onto the LINQ to SQL Classes.

img7.jpg

Figure 7.

Now add a new entity class called customers using right-click into LINQ-To-SQL data context.

img8.jpg

Figure 8.

Add properties using right-click and click Add Properties.

img9.jpg

Image 9.

img10.jpg

Figure 10.

Now time to bind the stored procedure with the customer class; right-click on the stored procedure and click on properties and select class name in ReturnType.

img11.jpg

Figure 11.

Now drag and drop GridView control onto the page.

<h2>
        Customers</h2>
<p>

<asp:GridViewID="CustomersGridView"runat="server">
</
asp:GridView>

</p>

protectedvoidPage_Load(object sender, EventArgs e)
    {
if (!Page.IsPostBack)
        {           
using (CustomersDataClassesDataContext customers = newCustomersDataClassesDataContext())
            {
List<CustomersList>CustomersList = customers.GetAllCustomers().ToList<CustomersList>();
CustomersGridView.DataSource = CustomersList;
CustomersGridView.DataBind();
            }
        }
    }

All set; now build and run the website to see the result.

img12.jpg

Figure 12.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor