Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does Linq to sql mean?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about what Linq to sql means. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

What is Linq to sql?

Linq to sql (or DLINQ) is a part of LINQ (.NET language Integrated query), which is fully called .NET language integrated query based on relational data. It is used to manage relational data in the form of objects, and provides rich query functions. It forms a powerful LINQ with Linq to xml, Linq to objects, Linq to dataset, Linq to entities and so on.

To learn LINQ query syntax well, you have to understand some of the new features of C # 3.0, which are briefly described below.

Linq to sql implied type local variable

Var age = 26; var username = "zhuye"; var userlist = new [] {"a", "b", "c"}; foreach (var user in userlist) Console.WriteLine (user)

The var keyword, which is purely for lazy people, tells the compiler (for CLR, it won't know if you use var, coolies are from the compiler), you can infer its type, I don't care. But since you want the compiler to infer that a type must be assigned when it is declared, it cannot be a null value. Note that this can only be used for local variables, not for fields.

Linq to sql anonymous type

Var data = new {username = "zhuye", age = 26}; Console.WriteLine ("username: {0} age: {1}", data.username, data.age)

Anonymous types allow developers to define inline types without having to explicitly define types. Often used with var, var is used to declare anonymous types. Defining a temporary anonymous type is very common in LINQ query syntax, and we can easily implement object conversion and projection.

Linq to sql extension method

Public static class helper

{

Public static string MD5Hash (this string s)

{

Return System.Web.Security.FormsAuthentication.

HashPasswordForStoringInConfigFile (s, "MD5")

}

Public static bool In (this object o, IEnumerable b)

{

Foreach (object obj in b)

{

If (obj==o)

Return true

}

Return false

}

}

/ / call the extension method

Console.WriteLine ("123456" .MD5Hash ())

Console.WriteLine ("1" .in (new [] {"1", "2", "3"}))

Many times we need to do some operations on the CLR type, because we cannot extend the methods of the CLR type, so we can only create some helper methods or generate subclasses. The extension approach enables these requirements to be implemented proudly, and is also the basis for the implementation of LINQ. It should be noted that extension methods can only be defined in static classes and are static methods. If the extension method name conflicts with the original method name, the extension method will become invalid.

Linq to sql automatic Properties

Public class Person {public string username {get; protected set;} public int age {get; set;} public Person () {this.username = "zhuye";}} Person p = new Person (); / / p.username = "aa"; Console.WriteLine (p.username)

The significance is not very great, purely solve the problem of mechanical labor. The compiler automatically generates get, set actions and fields for you, and you cannot use fields or customize get and set operations, but you can define access levels for get and set, respectively.

Thank you for reading! This is the end of this article on "what does Linq to sql mean?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report