.netTiers 的探索,数据访问的四种方式。

.netTiers 2.2,2.3中,在CodeSmith中设置注意:


IncludeComponentLayer, ServiceLayer
IncludeGenerateData, SQLserver2005

ComponentLayerNameSapce: Service

 

否则没有dataService层。

 

废话少说,代码如下。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="test1.Website._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Home Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        <asp:GridView ID="GridView1" runat="server">
     
        </asp:GridView>
       
            <asp:Label runat="server" Text="" ID="lbltext"></asp:Label>
        </div>
   
    </form>

</body>
</html>

 

CS

 

#region Using Directives
using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using test1.Services;
using test1.Entities;
using test1.Data;
#endregion

namespace test1.Website
{
    public partial class _Default : System.Web.UI.Page
    {
        /// <summary>
        /// Handles the Load event of the Page class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
  {

            CpTestHdRequirementDataService cds = new CpTestHdRequirementDataService();
            TList<CpTestHdRequirementData> CpHdList = cds.GetAll();
            GridView1.DataSource = CpHdList;
            GridView1.DataBind();
       
            //方式一: 使用系统Service层提供的各方法。
            //int outTitle = 0;
            //TList<CpTestHdRequirementData> CpHdList = cds.GetPaged("GroupName='SAP'", "Category DESC", 0, 100, out outTitle);
            //GridView1.DataSource = CpHdList;
            //GridView1.DataBind();

            //TList<CpTestHdRequirementData> CpHdList = cds.GetByOutId(3);
            //GridView1.DataSource = CpHdList;
            //GridView1.DataBind();

            //CpTestHdRequirementDataKey dataKey = new CpTestHdRequirementDataKey(3);
            //CpTestHdRequirementData cd = cds.Get(dataKey);

            //lbltext.Text = cd.Code;

            //CpTestHdRequirementData dd = new CpTestHdRequirementData();
            //dd.Category = "aa";
            //dd.Code = "bb";
            //dd.Contact = "cc";
            //dd.GroupName = "ddss";
            //dd.IsRun = "adsF";
            //dd.Otc = 8888;

            //cds.Insert(dd); //本方法还可以批量插入

            //lbltext.Text = dd.Id.ToString();

           // int outTitle = 0;
           //TList<CpTestHdRequirementData>  DelList = cds.GetPaged("GroupName='ddss'", "Category DESC", 0, 100, out outTitle);
           //cds.Delete(DelList);

            //CpTestHdRequirementData ss = cds.GetById(1);
            //ss.IsRun = "00000";

            //cds.Update(ss);

            //深调可以把一个表的所有外键相关链的表内容全部调出来
            //CpTestHdRequirementData dsdf = cds.DeepLoadById(1, true, test1.Data.DeepLoadType.IncludeChildren, typeof(CpTestOutKey), typeof(TList<CpTestOutKey>));
            //GridView1.DataSource = CpHdList;
            //GridView1.DataBind();

            //lbltext.Text = dsdf.OutIdSource.Value;

            //cds.DeepLoad(CpHdList); // deep load CpHdList;
            //GridView1.DataSource = CpHdList;
            //GridView1.DataBind();

            //方式二:使用存储过程命规则,重生成代码,代码自会生成相应的方法去调用存储过程.

            //DataSet dsList = DataRepository.CpTestHdRequirementDataProvider.getResultTest(3, 2010); // 使用自定义存储过程,只需将其命名为_TABLE_METHOD 生成代码。
            //GridView1.DataSource = dsList.Tables[1];
            //GridView1.DataBind();


            //方式三:利用Data层提供各表的Provider结合Entites,像Service层一使用方法。
            //DataRepository.CpTestHdRequirementDataProvider.Update(ddd ) // DataRepository Provider同样具有 Service层提的Get若干方法,insert,delete,save...          

 

     
            //方式四:Data层DataReposityory提供的最基本方法。
            string sqlCommand = "GetRequirementResult";
            DataSet ds = DataRepository.Provider.ExecuteDataSet(sqlCommand,3,2010);//DataRepsitory.Provider,执行存储过程的多数方法。ExecuteReade,ExecuteDataSet,ExecuteNonQuery 这种方式最终调用的是微软企业库去执行。Microsoft Enterparse Libera

          
            GridView1.DataSource = ds.Tables[1];
            GridView1.DataBind();
         
          
     }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值