C#webform LinQ

來源:互聯網
上載者:User

標籤:

LinQ的進階查詢:

模糊查

con.Car.Where(r=>r.Name.Contains(cname)).ToList();


以..開頭

con.car.Where(r => r.name.StartsWith(TextBox1.Text)).ToList();

 

以..結尾

con.car.Where(r => r.name.EndsWith(TextBox1.Text)).ToList();

 

求最大值

con.car.Max(r => r.price * r.oil).ToString();

 

最小值

con.car.Min(r => r.price).ToString();


求和

con.car.Sum(r => r.price).ToString();


平均值

con.car.Average(r => r.price).ToString();

 

升序

con.car.OrderBy(r => r.price).ToList();


降序

con.car.OrderByDescending(r => r.price).ToList();

 

分頁

int pageNum = Convert.ToInt32(PageCount_Label.Text) + 1;

Repeater1.DataSource = con.car.Skip((pageNum - 1) * PageCount).Take(PageCount);
Repeater1.DataBind();
PageCount_Label.Text = pageNum.ToString();

組合查詢

List<car> list = con.car.ToList();

if (TextBox2.Text != "")
{
List<car> list1 = con.car.Where(r => r.name.Contains(TextBox2.Text)).ToList();

list = list.Intersect(list1).ToList();
}
if (TextBox3.Text != "")
{
List<car> list1 = con.car.Where(r => r.oil == Convert.ToDecimal(TextBox3.Text)).ToList();

list = list.Intersect(list1).ToList();
}
if (TextBox4.Text != "")
{
List<car> list1 = con.car.Where(r => r.powers == Convert.ToInt32(TextBox4.Text)).ToList();

list = list.Intersect(list1).ToList();
}


Repeater1.DataSource = list;
Repeater1.DataBind();

 

C#webform LinQ

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.