LinqToSQL

Introduction to LINQ:

LINQ (Language Integrated Query) Language Integrated Query is a set of extensions for c # and Visual Basic languages. It allows you to write C # or Visual Basic code to operate the memory data the way to query the database.

LinqToSQL;

LINQ TO SQL Comprising one O in the .NET Framework version 3.5 / RM component (object-relational mapping), O / RM .NET class allows you to use to model the relational database.

From a technical point of view, approximately 40 defines the LINQ query operators, such as select, from, in, where and order by (C # in). These operators can use to write queries. However, these queries can also be based on many types of data, each data type requires a separate LINQ type.

Suitable for novice reference

Directly on the code:

[Table (Name = "Contack" )] // database table name owned by
public class Contack
{
[the Column]
public String the Title {GET; SET;} // the name of the table has fields, following the same
[the Column]
public String {GET FirstName; SET;}
[the Column]
public String the LastName {GET; SET;}
[the Column]
public String {MiddleName, GET; SET;}
[the Column]
public String the EmailAddress {GET; SET;}
}

System.Data.Linq introduction assembly;

DataContext Not here you can search for relevant sites in detail

Readonly the connectionString = static String Private
"connect string";

DataContext context = new DataContext(connectionString);
Table<Contack> contacts = context.GetTable<Contack>();//获取一个制定Table类型的集合
var query = from s in contacts.AsEnumerable()
select new { s.Title,s.LastName,s.MiddleName};

// About AsEnumerable (), because we have obtained is a collection of Table types, so it is necessary to convert it into a list collection to use linq statement operation

 

Guess you like

Origin www.cnblogs.com/jxl123456/p/11108732.html