Entity Framework底层操作封装(3)

上面谈了几个类的封装,这次我们讲讲使用的方式。

在实际过程中,我们怎么就能说明我们少了代码的编写呢?

例如我们需要一个类实现某个表的操作,我们只需要继承与我们的Base类就能实现了。

 

[csharp] view plaincopy
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using NOAS.PublicOpinionMonitor.Access.Common;  
  6. using NOAS.PublicOpinionMonitor.ENTITY;  
  7.   
  8. namespace NOAS.PublicOpinionMonitor.Access  
  9. {  
  10.     public class ProxyDAL : AccessBase<t_po_monitor_proxy>  
  11.     {  
  12.   
  13.         public ProxyDAL()  
  14.             : base(strTableName:"t_po_monitor_proxy",ColumsName:@" [monitorid]  
  15.                                                                   ,[monitor_name]  
  16.                                                                   ,[tkwid]  
  17.                                                                   ,[monitor_stardate]  
  18.                                                                   ,[monitor_enddate]  
  19.                                                                   ,[monitor_datetype]  
  20.                                                                   ,[monitor_interval]  
  21.                                                                   ,[data_begindate]  
  22.                                                                   ,[data_enddate]  
  23.                                                                   ,[exec_datetime]  
  24.                                                                   ,[monito_days]  
  25.                                                                   ,[updatedate]  
  26.                                                                   ,[status]")  
  27.         {  
  28.         }  
  29.   
  30.   
  31.   
  32.   
  33.         public List<t_po_monitor_proxy> getAllMonitorProxy()   
  34.         {  
  35.            return getListByWhere(string.Empty);  
  36.         }  
  37.   
  38.   
  39.           
  40.   
  41.     }  
  42. }  

我坚持的东西是,自己的事情自己做。所以一般在做底层的架构涉的时候,每个类只能操作自己对应的表。这样让我们的代码也会更加的清晰。

 

在业务层的使用过程中,就更加简单了。

 

[csharp] view plaincopy
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.   
  6. namespace NOAS.PublicOpinionMonitor.BIZ  
  7. {  
  8.     public class ProxyBLL  
  9.     {  
  10.         public int addMonitorProxy(ENTITY.t_po_monitor_proxy proxyEntity)   
  11.         {  
  12.   
  13.             new NOAS.PublicOpinionMonitor.Access.ProxyDAL().addEntity(proxyEntity);  
  14.             return proxyEntity.mproxyid;  
  15.   
  16.         }  
  17.   
  18.   
  19.   
  20.         public int updateMonitorProxy(ENTITY.t_po_monitor_proxy proxyEntity)  
  21.         {  
  22.   
  23.             new NOAS.PublicOpinionMonitor.Access.ProxyDAL().updateEntity(proxyEntity);  
  24.             return proxyEntity.mproxyid;  
  25.         }  
  26.     }  
  27. }  


从这里也让我更加的喜欢去设计和架构东西。架构让程序编程更美。多想,多做,多看。让我们的代码变得更加清晰。

 

坚决不做码农,我们是攻城师。

posted @ 2014-12-30 15:17  关中秦人  阅读(110)  评论(0编辑  收藏  举报