posts - 82, comments - 0, trackbacks - 0

My Links

News

Archives

Post Categories

C# Download

Facebook

Informativa cookie

Linkedin

Microsoft

Msdn Gallery

Twitter

VisualBasic

Wiki Tecknet

Using the Join clause

/ / Example of Linq query
/ / Join
/ / The join clause allows you to associate different datasource based on a member. Can not
/ / Compare with the join clause with more than, less than, other, only comparisons of epoxy
/ / Equality.
/ / This example of using Linq query the join clause compares the index of the matrix customers Job
/ / Position of the matrix with the index work, returning a list of customers with the same job that includes the name, title, and
/ / The level of all customers.

/ / Call the operating system NameSpace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/ / Namespace Linq_join_
namespace Linq_join_
{
   
/ / Class Program
    
class Program
    
{
       
/ / Main Method Static
        
static void Main (string [] args)
       
{
           
/ / Call method Union
            
Union ();
       
}
 
        
/ / Method Static Union
        
public static void Union ()
       
{
 
            
/ / Matrix customers
            
var customers = new []
           
{
           
/ / Declaration of matrix 1 customer Nationomality
            
new {CustomerID = 1, Name = "Customer1", Job = "Electrician"},
           
/ / Statement 2 of customer matrix Nationomality
           
new {CustomerID = 2, Name = "Customer2", Job = "tuba"},
           
/ / Declaration of Matrix 3 customer Nationomality
           
new {CustomerID = 3, Name = "Customer3", Job = "Plumber"},
           
/ / Declaration of the matrix 4 customer Nationomality
           
new {CustomerID = 4, Name = "Customer4", Job = "Mechanical"},
           
/ / Declaration of the matrix 5 customer Nationomality
           
new {CustomerID = 5, Name = "Customer5", Job = "Softer"},
           
/ / Declaration of the matrix 6 customer Nationomality
           
new {CustomerID = 6, name = "Customer6", Job = "Instrumentalist"},
           
};
 
            
/ / Work array
            
var work = new []
           
{
           
/ / Statement 1 customer work on matrix
            
New workID = {1, Job = "Electrician", Level = "Fourth"},
           
/ / Declaration 2 customer work on matrix
            
workID = new {2, Job = "tuba", Level = "Fourth"},
           
/ / Statement 3 customer work on matrix
           
New workID = {3, Job = "Plumber" Level = "Fourth"},
           
/ / Statement 4 customer work on matrix
           
New workID = {4, Job = "Mechanical," Level = "Fourth"},
           
/ / Statement 5 customer work on matrix
           
New workID = {5, Job = "Softer" Level = "Fourth"},
           
/ / Declaration of the matrix 6 customer work
           
New workID = {6, Job = "Softer" Level = "Fourth"},
           
};
 
            
/ / Select data from array of customers, and if the job vrrifica of customers and equal
           
/ / Work to the task of the matrix, and then returns a list of the names, and Job Level.
            
var customers = custom.
            
/ / Select clause, which is selected by the parameter c of the matrix and job ninth customers
            
Select (c =>
           
c.Nome new {,} c.Mansione)
           
/ / Do the comparison between the variable customers and work
            
. Join (work, custs => custs.Mansione, job => job.Mansione (custs, job) =>
           
/ / Return the list of matches found after comparing
            
new {custs.Nome, job.Mansione, job.Livello});
           
/ / Variable number of customers found support
            
iCustomers int = 0;

           
/ / Retrieve data from custom variable and passes them to row
            
foreach (var row in custom)
           
{
               
/ / Increment number of customers found varying support
                
iCustomers + +;
               
/ / Display to user name, customer and as a matrix of variable-Level Job and work
                
Console.WriteLine ("Customer number" + '\ t' + iCustomers.ToString () + '\ t' + row.Nome + '\ t' + row.Mansione + '\ t' + row.Livello);
            
}
 
            
/ / Blank line
            
Console.WriteLine ();
           
/ / Blank line
            
Console.WriteLine ("Press any key to exit");
           
/ / Wait for any key from keyboard
            
Console.ReadLine ();
       
}
   
}
}

Print | posted on domenica 3 luglio 2011 20:39 | Filed Under [ Articles in English Linq ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 3 and 6 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET