Linq調(diào)用數(shù)據(jù)訪(fǎng)問(wèn)服務(wù)
Linq有很多值得學(xué)習(xí)的地方,這里我們主要介紹Linq調(diào)用數(shù)據(jù)訪(fǎng)問(wèn)服務(wù),包括介紹Admin.cs代碼修改成等方面。
Linq調(diào)用數(shù)據(jù)訪(fǎng)問(wèn)服務(wù)
Linq調(diào)用數(shù)據(jù)訪(fǎng)問(wèn)服務(wù)來(lái)進(jìn)行留言、回復(fù)、刪除留言等操作了。頁(yè)面的代碼不再貼了,我們把Default.cs修改成如下:
- public partial class _Default : System.Web.UI.Pag
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- SetBind();
- }
- }
- protected void btn_SendMessage_Click(object sender, EventArgs e)
- {
- TbGuestBook gb = new TbGuestBook();
- gb.ID = Guid.NewGuid();
- gb.IsReplied = false
- gb.PostTime = DateTime.Now;
- gb.UserName = tb_UserName.Text;
- gb.Message = tb_Message.Text;
- GetService.GetDataAccessService().SendMessage(gb);
- SetBind();
- }
- private void SetBind()
- {
- rpt_Message.DataSource = GetService.GetDataAccessService().GetData();
- rpt_Message.DataBind();
- }
- }
Admin.cs代碼修改成如下:
- public partial class Admin : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- SetBind();
- }
- }
- private void SetBind()
- {
- rpt_Message.DataSource = GetService.GetDataAccessService().GetData();
- rpt_Message.DataBind();
- }
- protected void rpt_Message_ItemCommand(object source, RepeaterCommandEventArgs e)
- {
- if (e.CommandName == "DeleteMessage")
- {
- GetService.GetDataAccessService().DeleteMessage(e.CommandArgument.ToString());
- SetBind();
- }
- if (e.CommandName == "SendReply")
- {
- TbGuestBook gb = new TbGuestBook();
- gb.ID = new Guid(e.CommandArgument.ToString());
- gb.Reply = ((TextBox)e.Item.FindControl("tb_Reply")).Text
- GetService.GetDataAccessService().SendReply(gb);
- SetBind();
- }
- }
- }
就這樣實(shí)現(xiàn)了一個(gè)多層構(gòu)架的留言簿程序。對(duì)于WCF的一些內(nèi)容本文不多作解釋了。如果您覺(jué)得這個(gè)例子太簡(jiǎn)單,還可以在這里下載一個(gè)Linq/WCF/MVC結(jié)合使用更復(fù)雜的例子,此例的目的主要演示一個(gè)框架,實(shí)現(xiàn)不完整。以上介紹Linq調(diào)用數(shù)據(jù)訪(fǎng)問(wèn)服務(wù)。
【編輯推薦】