學(xué)習(xí)LINQ基本操作的一點體會
學(xué)習(xí)LINQ基本操作 ,其實主要就是LINQ更新、插入以及刪除的相關(guān)操作,那么具體的實現(xiàn)過程是什么呢?我們在具體的過程中需要注意什么呢?網(wǎng)上有很多資料,這里向你介紹一些,希望對你有所幫助。
LINQ基本操作學(xué)習(xí)1.
我首先創(chuàng)建一個表,名字為:userinfo的表。
LINQ基本操作學(xué)習(xí)2.
將表拉到vs 2008的linq file上面,然后保存一下,你會看到如下圖,ms利用拖放式方法,生成表對應(yīng)的類,這個比nhibername方便多了。只要你一保存它就會自動自成一個class。
LINQ基本操作學(xué)習(xí)3.編寫代碼:
LINQ基本操作代碼如下:
- public partial class TestLinQ_Default : System.Web.UI.Page
- ...{
- GetUserInfoDataContext cxt =
- new GetUserInfoDataContext(
- System.Configuration.ConfigurationManager.
- ConnectionStrings["TestConnectionString"].ToString());
- protected void Page_Load(object sender, EventArgs e)
- ...{
- }
- //LINQ基本操作插入操作
- protected void Button1_Click(object sender, EventArgs e)
- en_Text'').style.display=''inline'';" align="top" alt=""
- src="http://images.csdn.net/syntaxhighlighting/
- OutliningIndicators/ContractedSubBlock.gif" />...{
- UserInfo userinfo = new UserInfo();
- userinfo.username = TextBox1.Text;
- userinfo.password = TextBox2.Text;
- cxt.UserInfos.InsertOnSubmit(userinfo);
- cxt.SubmitChanges();
- // cxt.InsertUserInfo(TextBox1.Text, TextBox2.Text);
- }
- //LINQ基本操作之刪除操作
- protected void Button2_Click(object sender, EventArgs e)
- ...{
- UserInfo userinfo =
- cxt.UserInfos.Single(b => b.id == int.Parse(txt_id.Text));
- cxt.UserInfos.DeleteOnSubmit(userinfo);
- cxt.SubmitChanges();
- }
- //LINQ基本操作之更新操作protected void Button3_Click(object sender, EventArgs e)
- splay=''inline'';
- document.getElementById(''_947_1210_Closed_Text'').
- style.display=''inline'';" align="top" alt="" src=
- "http://images.csdn.net/syntaxhighlighting/
- OutliningIndicators/ExpandedSubBlockStart.gif" />...{
- UserInfo userinfo =
- cxt.UserInfos.Single(b => b.id ==
- int.Parse(txt_update_id.Text));
- userinfo.username = txt_update_username.Text;
- userinfo.password = txt_update_password.Text;
- // cxt.UserInfos.
- cxt.SubmitChanges();
- }
- }
LINQ基本操作學(xué)習(xí)的一些內(nèi)容就向你介紹到這里,希望對你了解和學(xué)習(xí)LINQ基本操作有所幫助。
【編輯推薦】