NetTiers学习笔记08---Entity层的扩展和EntityDataSource的使用方法

本文探讨了在.NET实体框架中实现DeepLoad的方法,并详细解释了一个具体的实例:如何通过DeepLoad获取ContractPersonName属性。此外,还展示了如何配置实体数据源以支持分页、排序等功能。
扩展1个属性 ContractPersonName , 这个属性需要Deepload Users表 才能得到
所以加了判断,如果没有DeepLoad则会抛出异常
 1       public  partial  class  Contract : ContractBase
 2      {
 3           #region  Constructors
 4 
 5           /// <summary>
 6           ///  Creates a new  <see cref="Contract"/>  instance.
 7           /// </summary>
 8           public  Contract() :  base () { }
 9 
10 
11           #endregion
12 
13           ///   <summary>
14           ///  合同签约人 - -b 名字比较烂
15           ///   </summary>
16           public   string  ContractPersonName
17          {
18               get
19              {
20                   if  ( this .FContractPerson  !=   null   &&   this .FContractPersonSource  ==   null )
21                       throw   new  Exception( " 没有使用Deepload " );
22 
23                   if  ( this .FContractPerson  ==   null )
24                       return  String.Empty;
25 
26                   return   this .FContractPersonSource.FName;
27              }
28          }
29 
30      }

建一个实体数据源和一个GridView,允许DeepLoad但不允许递归,不允许事务,允许分页和排序,使用GetPaged方法进行查询
DeepLoad Users对象,再添加5个参数,4个输入,1个输出,PageIndex,OrderBy和PageSize都取GridView的属性
最后再添加一个过滤的参数... 
 1  < asp:DropDownList  ID ="NameList"  AutoPostBack ="true"  runat ="server" >
 2       < asp:ListItem  Value ="" > All </ asp:ListItem >
 3       < asp:ListItem > iCaca </ asp:ListItem >
 4       < asp:ListItem > Sun </ asp:ListItem >
 5       < asp:ListItem > Grubby </ asp:ListItem >
 6       < asp:ListItem > Sky </ asp:ListItem >
 7       < asp:ListItem > Moon </ asp:ListItem >
 8  </ asp:DropDownList >
 9  < data:ContractDataSource  ID ="source"  runat ="server"  EnablePaging ="True"  EnableSorting ="True"
10      EnableTransaction ="False"  SelectMethod ="GetPaged"  EnableDeepLoad ="True" >
11       < DeepLoadProperties  Method ="IncludeChildren"  Recursive ="False" >
12           < Types >
13               < data:ContractProperty  Name ="Users"   />
14           </ Types >
15       </ DeepLoadProperties >
16       < Parameters >
17           < data:SqlParameter  Name ="WhereClause"  UseParameterizedFilters ="false" >
18               < Filters >
19                   < data:ContractFilter  Column ="FContractPerson"  ControlID ="NameList"   />
20               </ Filters >
21           </ data:SqlParameter >
22           < asp:ControlParameter  Name ="OrderBy"  ControlID ="GridView1"  PropertyName ="SortExpression"
23              Type ="String"   />
24           < asp:ControlParameter  Name ="PageIndex"  ControlID ="GridView1"  PropertyName ="PageIndex"
25              Type ="Int32"   />
26           < asp:ControlParameter  Name ="PageSize"  ControlID ="GridView1"  PropertyName ="PageSize"
27              Type ="Int32"   />
28           < asp:Parameter  Name ="RecordCount"  Type ="Int32"   />
29       </ Parameters >
30  </ data:ContractDataSource >
31  < asp:GridView  ID ="GridView1"  runat ="server"  AllowPaging ="True"  DataKeyNames ="FId"
32      DataSourceID ="source"  AllowSorting ="True" >
33       < Columns >
34           < asp:BoundField  DataField ="ContractPersonName"   />
35       </ Columns >
36  </ asp:GridView >
37 

到底是网页绑定好还是后台绑定好,也要看具体的情况而定~
如果太复杂...还是后台吧...

转载于:https://www.cnblogs.com/iCaca/archive/2007/07/10/812632.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值