MyGeneration学习笔记(6) :在Web Service中使用dOOdad(下)

简介:


       上一篇文章讲述了怎样插入一条记录,这里补充一下查询、修改和删除一条记录。相对插入而言,查询、修改和删除容易得多,下面分别给出我的一种实现:

 

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);

 

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());

 

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;
    }

}


         现在还没有好的dOOdads模板来生成支持Web Service的业务实体,相信不久的将来会有的……

 本文转自Silent Void博客园博客,原文链接:http://www.cnblogs.com/happyhippy/archive/2006/08/23/601236.html,如需转载请自行联系原作者

相关文章
|
18天前
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
|
18天前
|
关系型数据库 MySQL Linux
【Azure 应用服务】在创建Web App Service的时候,选Linux系统后无法使用Mysql in App
【Azure 应用服务】在创建Web App Service的时候,选Linux系统后无法使用Mysql in App
【Azure 应用服务】在创建Web App Service的时候,选Linux系统后无法使用Mysql in App
|
17天前
|
Shell PHP Windows
【Azure App Service】Web Job 报错 UNC paths are not supported. Defaulting to Windows directory.
【Azure App Service】Web Job 报错 UNC paths are not supported. Defaulting to Windows directory.
|
18天前
|
Linux 应用服务中间件 网络安全
【Azure 应用服务】查看App Service for Linux上部署PHP 7.4 和 8.0时,所使用的WEB服务器是什么?
【Azure 应用服务】查看App Service for Linux上部署PHP 7.4 和 8.0时,所使用的WEB服务器是什么?
|
18天前
【Azure 应用服务】通过 Web.config 开启 dotnet 应用的 stdoutLog 日志,查看App Service 产生500错误的原因
【Azure 应用服务】通过 Web.config 开启 dotnet 应用的 stdoutLog 日志,查看App Service 产生500错误的原因
|
18天前
|
Linux Python
【Azure 应用服务】Azure App Service For Linux 上实现 Python Flask Web Socket 项目 Http/Https
【Azure 应用服务】Azure App Service For Linux 上实现 Python Flask Web Socket 项目 Http/Https
|
18天前
|
存储 安全 网络安全
【Azure 环境】使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢(Microsoft Antimalware)?
【Azure 环境】使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢(Microsoft Antimalware)?
|
18天前
|
存储 Linux 网络安全
【Azure 应用服务】App Service For Linux 如何在 Web 应用实例上住抓取网络日志
【Azure 应用服务】App Service For Linux 如何在 Web 应用实例上住抓取网络日志
|
18天前
【Azure 云服务】Azure Cloud Service 为 Web Role(IIS Host)增加自定义字段 (把HTTP Request Header中的User-Agent字段增加到IIS输出日志中)
【Azure 云服务】Azure Cloud Service 为 Web Role(IIS Host)增加自定义字段 (把HTTP Request Header中的User-Agent字段增加到IIS输出日志中)
|
18天前
|
Web App开发 安全 JavaScript
【Azure 应用服务】App Service 通过配置web.config来添加请求返回的响应头(Response Header)
【Azure 应用服务】App Service 通过配置web.config来添加请求返回的响应头(Response Header)