LinQ various database query methods

Source: Internet
Author: User

1, multi-criteria query:
and &&
or | |

var list = Con.car.Where (r = R.code = = "c014" | | r.oil = = 8.2M);


2. Fuzzy query
1. Blur
var list = Con.car.Where (r = R.name.contains ("at"));
2. Opening
var list = Con.car.Where (r = R.name.startswith ("crown"));
3. End
var list = Con.car.Where (r = R.name.endswith ("version"));


3. Statistical inquiry
1. Total number
var count = Con.car.Count ();
2. Maximum Value
var Max = Con.car.Max (r = r.price);
3. Minimum value
var Min = con.car.Min (r = r.price);
4. Average
var avg = con.car.Average (r = r.price);

4, paging query
Skip, get
int count = 5; Define a variable to use as the number of bars to display per page
int pagecount = 0;

var list = Con.car.Skip (PageCount * Count skips how many bars). Take (count takes how many bars);
A PageCount is 0, it multiplied by the number of bars is skipped how many, the first to skip 0, take Count Bar, is the first page display content, when PageCount becomes 1,
The second is to skip the Count bar, and then take the Count bar after the bar, that is, skip the first page to show the number of bars, and then skip the first page after the number of these bars, it is the next page


5, sort query
Ascending
//var list = con.car.OrderBy (r = r.price);//Sort a column of numeric types in a database table
Descending
//var list = Con.car.OrderByDescending (r = r.price);

de-weight:
var aaa = Con.car.Select (r = r.oil). Distinct ();

6, foreign key display
return this.brand1.brand_name;//in a table with a primary foreign key relationship, when querying the foreign key table, you can point out the value of any column in the primary key table, and if the primary key table is a foreign key of
other tables, you can also continue the point

7, combined query
intersection
var list = List1. Intersect (List2). Intersect (LIST3);
-------------------------------------------------------------
var list1 = con.car.AsQueryable ();
Var List2 = Con.car.AsQueryable ();
var list3 = con.car.AsQueryable ();

if (TextBox1.Text.Trim (). Length > 0)
{
List1 = List1. Where (r = R.name.contains (TextBox1.Text.Trim ()));
}
if (TextBox2.Text.Trim (). Length > 0)
{
List2 = List2. Where (r = r.brand1.brand_name. Contains (TextBox2.Text.Trim ()));
}
if (TextBox3.Text.Trim (). Length > 0)
{
List3 = List3. Where (r = R.oil = = Convert.todecimal (TextBox3.Text.Trim ()));
}

var list = List1. Intersect (List2). Intersect (LIST3);

Repeater1.datasource = list;
Repeater1.databind ();

LinQ various database query methods

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.