Add an alias to a field in linq, and add an alias to a field in linq

Source: Internet
Author: User

Add an alias to a field in linq, and add an alias to a field in linq

Linq is a form that we often use in queries. For example, we create a class, and then List <add> and bind it to the table.
Public class Modeltest {string id; public string Id {get {return id;} set {id = value ;}} string pwd; public string Pwd {get {return pwd ;} set {pwd = value ;}} string name; public string Name {get {return name ;}set {name = value ;}}}

Generally, we bind data to tables such as DataSource = list or datase. In this way, the field name of the table is the id declared in your class, pwd. this is not easy to understand, especially when the number of fields increases and multi-table join queries occur.

In this case, how do we write data using linq?

Var I = from u in list select new {No. = u. id, password = u. pwd, name = u. name}; sponse = I. toarray ();

In this way, the field name of your table is defined by yourself.

Here, I use the c/s datagridview in the B/s end, in fact, the usage of the linq is the same, when you don't want to give a field alias in SQL, it is a good choice to give the alias in linq.

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.