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.