(LINQ) (7) Examples of the LINQ Tutorial: Multi-table join operations of LINQ

Source: Internet
Author: User

 

1. Create two Relational Tables, student and class tables. Students and course schedules, as shown in the example.

 

2. Create a form in vs2010.

 
And writeCodeAs follows:

Namespace Linqtest
{
Public Partial Class Frmmanytomany: Form
{
Internal Static String Sqlconstr = @" Data Source = localhost; initial catalog = lxpower; user = sa; Pwd = " ;
Public Frmmanytomany ()
{
Initializecomponent ();
}

Private VoidFrmmanytomany_load (ObjectSender, eventargs E)
{
Binddata ();
}

Private Void Binddata ()
{
Dataclasses1datacontext DB =New Dataclasses1datacontext (sqlconstr );
VaR Q = From C In DB. Student
Join o In DB. oclass on C. studentname equals O. studentname
Select New {C. ID, C. studentname, O. Class };
This . Maid = Q;
}
}
}

Here we use the LINQ to SQL statement. In fact, you can use datacontent for relational purposes.

The running result is as follows::

 

 

Is the relationship between the two tables very simple and may encounter many problems in actual operations? We can discuss the following:

 

For original works, please indicate the source for reprinting !!!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.