MyGeneration学习笔记(6) :在Web Service中使用dOOdad(下)
来源:互联网 发布:js遍历list对象集合 编辑:程序博客网 时间:2024/05/22 20:27
上一篇文章讲述了怎样插入一条记录,这里补充一下查询、修改和删除一条记录。相对插入而言,查询、修改和删除容易得多,下面分别给出我的一种实现:
1.查询:
//WebService端代码:
[WebMethod]
public string GetEmployee(int empID)
...{
Employee emp = new Employee();
if(emp.LoadByPrimaryKey(empID))
...{
return emp.ToXml();
}
else
...{
return null;
}
}
//客户端代码:
webService service = new webService();
Employee emp = service.GetEmployee(int empID);
[WebMethod]
public string GetEmployee(int empID)
...{
Employee emp = new Employee();
if(emp.LoadByPrimaryKey(empID))
...{
return emp.ToXml();
}
else
...{
return null;
}
}
//客户端代码:
webService service = new webService();
Employee emp = service.GetEmployee(int empID);
2. 更新:
ADO.Net 2.0中新增了一项功能:DataRow提供SetModified和SetAdded方法来改变其状态。上一篇文章中讲到,执行emps.FromXml之后,DataRow的状态为Added,这里我们可以将DataRow的状态改为Modified,当调用Save时,即可实现更新功能。
//BusinessEntity.cs中添加一个函数:
virtual public void MarkAsModified()
...{
if (_dataRow != null)
...{
_dataRow.SetModified();
}
}
//WebService端的代码:
[WebMethod]
public bool Update(string str)
...{
Employee emp = new Employee();
emps.FromXml(str); //此时DataRow的状态为Added
emps.AcceptChanges(); //此时DataRow的状态为Unchanged
emps.SetModified(); //此时DataRowd的状态为Modified
emps.Save(); //保存修改
}
//客户端代码:
webService service = new webService();
Employee emp = service.GetEmployee(int empID);//同上面的查询
emp.Property = …………;
service.Update(emp.Toxml());
virtual public void MarkAsModified()
...{
if (_dataRow != null)
...{
_dataRow.SetModified();
}
}
//WebService端的代码:
[WebMethod]
public bool Update(string str)
...{
Employee emp = new Employee();
emps.FromXml(str); //此时DataRow的状态为Added
emps.AcceptChanges(); //此时DataRow的状态为Unchanged
emps.SetModified(); //此时DataRowd的状态为Modified
emps.Save(); //保存修改
}
//客户端代码:
webService service = new webService();
Employee emp = service.GetEmployee(int empID);//同上面的查询
emp.Property = …………;
service.Update(emp.Toxml());
3. 删除:
//客户端只需将ID发过来就可以了
[WebMethod]
public bool Delete(int empID)
...{
Employee emp = new Employee();
if(emp.LoadByPrimaryKey(empID))
...{
emp.MarkAsDeleted();
emp.Save();
return true;
}
else
...{
return false;
}
}
[WebMethod]
public bool Delete(int empID)
...{
Employee emp = new Employee();
if(emp.LoadByPrimaryKey(empID))
...{
emp.MarkAsDeleted();
emp.Save();
return true;
}
else
...{
return false;
}
}
现在还没有好的dOOdads模板来生成支持Web Service的业务实体,相信不久的将来会有的……
- MyGeneration学习笔记(6) :在Web Service中使用dOOdad(下)
- MyGeneration学习笔记(6) :在Web Service中使用dOOdad(下)
- MyGeneration学习笔记(5) :在Web Service中使用dOOdad(中)
- MyGeneration学习笔记(5) :在Web Service中使用dOOdad(中)
- MyGeneration学习笔记(4) :在Web Service中使用dOOdad(上)
- MyGeneration学习笔记(4) :在Web Service中使用dOOdad(上)
- MyGeneration学习笔记(9) :在WebService使用dOOdad时,对ToXml/FromXml的一点改进
- MyGeneration学习笔记(9) :在WebService使用dOOdad时,对ToXml/FromXml的一点改进
- MyGeneration学习笔记(2) : 使用dOOdad提供的通用操作
- MyGeneration学习笔记(2) : 使用dOOdad提供的通用操作
- MyGeneration学习笔记(7) :dOOdad的String Properties和动态查询
- MyGeneration学习笔记(8) :dOOdad提供的数据绑定、特殊函数和事务处理
- MyGeneration学习笔记(7) :dOOdad的String Properties和动态查询
- MyGeneration学习笔记(8) :dOOdad提供的数据绑定、特殊函数和事务处理
- Java for Web学习笔记(七一):Service和Repository(6)在Spring框架中使用Listener
- MyGeneration学习笔记
- MyGeneration学习笔记(1) : 使用MyGeneration生成存储过程和数据访问层代码
- MyGeneration学习笔记(1) : 使用MyGeneration生成存储过程和数据访问层代码
- 孙鑫VC++讲座笔记-(2)C++
- 走出hq
- 微软发布简化版Xbox 360游戏开发工具XNA Game Studio
- 微软发布VS.NET 2003 SP1
- 经典--锤子的故事
- MyGeneration学习笔记(6) :在Web Service中使用dOOdad(下)
- 信阳名人
- Google对付桥页作弊的方法
- 维基百科的 Nuva 语言介绍
- (转)Delphi之东进模拟语音卡(D160A)可复用源码
- 程序人生
- (转)Delphi之东进模拟语音卡(D160A)可复用源码
- 上传图片时预览
- 孙鑫VC++讲座笔记-(3)MFC程序框架的剖析