[10 days to learn about Linq to SQL] day 1-Basic Knowledge

Source: Internet
Author: User

Directory

[10 days to learn about Linq to SQL] day 1-Basic Knowledge [10 days to learn about Linq to SQL] The next day -- data context [10 days to learn about Linq to SQL] The third day -- Data Query

[10 days to learn about Linq to SQL] the fourth day -- Data Update

[10 days to learn about Linq to SQL] day 6-Stored Procedure

No. 1. What is Linq to SQL ??

Before learning new things, you must know what you are learning and how to use it. The following is the materials from [Baidu encyclopedia;

Linq to SQL is included in.. NET Framework 3.5 is an O/RM component (Object link ing.. NET class. Then, you can use LINQ to query, update, add, and delete data in the database. Linq to SQL provides full support for transactions, views, and stored procedures. It also provides a simple implementation method for integrating the data validation and business layer logic into your data model. In LINQ to SQL, the relational database data model is mapped to the object model represented by the programming language used by developers. When the application is running, LINQ to SQL converts the language integration query in the object model to SQL, and then sends them to the database for execution. When the database returns the results, LINQ to SQL converts them back to objects that can be processed in your own programming language.

Have you understood it? It doesn't matter if you don't understand it. You can learn and understand it in the next tutorial.

 

No. 2,Implicit type local variable

 

 Age =  UserName=  Userlist =  [] {,,};

 

The word "var" is very familiar. It is often used in javascript (the language is something that is the same, especially the advanced language). Of course, the var and javascript var in C # are quite different.

1,It can only be used as a local variable.That is to say, var can only be defined in methods, loops, and other statements;

2. var can declare any type of variable and determine its type based on the subsequent initialization data without explicitly defining the type.(Is it like an object, but var is a strong type );

 UserData =  {Username = ,Age = };

3,Expression Initialization is required during var declaration;(Just like if my wife has children, you always have to know if it is a boy or a girl !)

That is, it must be defined as var I = 0. If no initialization compilation is performed, an error will be reported, and the initialization value cannot be null. the compiler cannot deduce the type of a Variable Based on null. The initial value except int, in addition to data types such as string, you can also use a new object as the initial value. (according to the comments posted on the Internet, the most common use of var is to use it with an anonymous object, and used in Linq );

// Below is a blog written by a netizen on the Internet. Copy and modify it!

Use with the anonymous type:

 a = { Name =  ,Age =

Applications in linq:

[] numbers = { , , , , , , , , ,  queryLowNums =     num  num <      ( s +  

4. Notes

Generally, var is not used like "var I = 9;", and the program is not highly readable;

It is more convenient to use the anonymous type; it is also good to use in foreach;

Var is just a language-level thing. The compiler will deduce it to a real type during compilation.

 

No. 3. LambdaExpression

 

C #2005, released with VS 2.0, introduced the concept of the anonymous method, allowing the use of the "in-line" code block (code blocks) in the expected proxy value) for replacement.

Lambda expressions provide more concise functional syntaxes for writing anonymous methods, but the results are extremely useful when writing a LINQ query expression, because they provide a very compact and class-safe method to write functions that can be passed as parameters for future computation.

Lambda expressions are actually anonymous functions. It contains expressions and statements and is often used to create a delegate or expression directory tree type. All Lambda expressions use the Lambda operator ---------- =>, which reads "goesto ". The left side of the Lambda operator is the input parameter (which may not exist), and the right side is the expression or statement block. The Lambda expression returns the result of the right expression.

 

           List<Student> student =  List<Student> Student{Name=,Age= Student{Name=,Age= Student{Name=,Age=         IEnumerable<Student> stu = student.Where(s => s.Name ==        Name { ;   Age { ; 

 

The highlighted red s => expression above is a Lambda expression. In the preceding example, lambda is used to specify the filter conditions used to obtain specific students;

Lambda expressions will learn this for the time being, because I do not know how to express what I have learned. I will use it in the next tutorial.

No. 4. query syntax

The query syntax is a convenient declarative and simplified way of writing a query using the standard LINQ query operator. This syntax can add readability and conciseness when expressing queries in code, which is easy to read and easy to write. Visual Studio provides complete intelligent sensing and compile-time check support for query syntaxes. At the underlying layer, the compiler translates the query syntax expression into a clear method call code. The code is implemented through new extension methods and Lambda expression language features.

           List<Student> student =  List<Student> Student{Name=,Age= Student{Name=,Age= Student{Name=,Age=            stu2 =  std  std.Name ==                                   stu = student.Where(s => s.Name == );

 

The query syntax of query 1 is equivalent to query 2;

The syntax of a linq query can achieve more than 90% of the functionality of a T-SQL (because the T-SQL is based on a two‑dimensional table, so the query syntax of LINQ is simpler and more flexible than the T-SQL), but due to intelligent sensing, select cannot be input at the beginning.

 


It is really not easy to write a tutorial, but after I write it once, I will know my shortcomings in that knowledge point, and I can improve my memory and correct my shortcomings. No matter what I write, I will stick to it.

I hope you can provide more support.

Related Article

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.