Introduzione

Usando LINQ to SQL è possibile avvalersi della tecnologia LINQ per accedere ai database SQL come se si trattasse di una raccolta in memoria.

Ad esempio, l'oggetto nw nel codice seguente viene creato per rappresentare il database Northwind, viene usata Customers come tabella di destinazione, le righe vengono filtrate in base a Customers residenti a London e viene selezionata una stringa da recuperare relativa a CompanyName.

Quando viene eseguito il ciclo, viene recuperata la raccolta di valori CompanyName.

// Northwnd inherits from System.Data.Linq.DataContext.
Northwnd nw = new Northwnd(@"northwnd.mdf");
// or, if you are not using SQL Server Express
// Northwnd nw = new Northwnd("Database=Northwind;Server=server_name;Integrated Security=SSPI");

var companyNameQuery =
    from cust in nw.Customers
    where cust.City == "London"
    select cust.CompanyName;

foreach (var customer in companyNameQuery)
{
    Console.WriteLine(customer);
}
' Northwnd inherits from System.Data.Linq.DataContext.
Dim nw As New Northwnd("c:\northwnd.mdf")
' or, if you are not using SQL Server Express
' Dim nw As New Northwnd("Database=Northwind;Server=dschwart7;Integrated Security=SSPI")

Dim companyNameQuery = _
    From cust In nw.Customers _
    Where cust.City = "London" _
    Select cust.CompanyName

For Each customer In companyNameQuery
    Console.WriteLine(customer)
Next

Passaggi successivi

Per alcuni esempi aggiuntivi, tra cui l'inserimento e l'aggiornamento, vedere Operazioni che è possibile intraprendere con LINQ to SQL.

Provare quindi a eseguire alcune procedure dettagliate ed esercitazioni per acquisire un'esperienza pratica relativa all'utilizzo di LINQ to SQL. Vedere Apprendimento tramite procedure dettagliate.

Infine, apprendere come iniziare a usare il progetto LINQ to SQL leggendo Passaggi tipici per l'uso di LINQ to SQL.

Vedi anche