一,向中间代码添加业务逻辑
在RIA service中通常会涉及到一些业务逻辑不需要客户端调用,但中间层又不可或缺,也就是只在中间层中访问,客户端不需要访问,不需要将该方法公开为服务,使用 IgnoreAttribute 特性来标记该方法,这个在客户端不可见,下面的演示将添加一个新的应用,(如果应用名称不重复)该方法使用 IgnoreAttribute 特性进行了标记,以防止从客户端将该方法作为服务调用。
1 /// <summary>
2
3 /// 判断是否存在相同的应用名称
4 /// </summary>
5 /// <param name="name"></param>
6 /// <returns></returns>
7 [Ignore]
8 public bool isExist(string name)
9 {
10 var temp = this.ObjectContext.BSMG_T_Content.Where(c => c.Name == name).OrderByDescending(c => c.ID).FirstOrDefault();
11 return temp == null ? false : true;
12 }
13 /// <summary>
14 /// 添加应用
15
16 /// </summary>
17 /// <param name="bSMG_T_Content"></param>
18 public void InsertBSMG_T_Content(BSMG_T_Content bSMG_T_Content)
19 {
20 if (!this.isExist(bSMG_T_Content.Name))//调用isExist()方法
21 {
22 if ((bSMG_T_Content.EntityState != EntityState.Detached))
23 {
24 this.ObjectContext.ObjectStateManager.ChangeObjectState(bSMG_T_Content, EntityState.Added);
25 }
26 else
27 {
28 this.ObjectContext.BSMG_T_Content.AddObject(bSMG_T_Content);
29 }
30 }
31 }