这是主要的开发模式:

/* 创建者:菜刀居士的博客
 * 创建日期:2014年07月06号
 */

namespace Net.CRM.OrganizationService
{
    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;

/// <summary>
    /// 基本模式---OrganizationService
    /// </summary>
    public class OrganizationServiceDemo
    {
        /// <summary>
        /// 查询
        /// </summary>
        public Entity Retrieve(IOrganizationService service, Entity en)
        {
            return service.Retrieve(en.LogicalName, en.Id, new ColumnSet("new_int", "new_string"));
        }

/// <summary>
        /// 删除
        /// </summary>
        public void Delete(IOrganizationService service, Entity en)
        {
            service.Delete(en.LogicalName, en.Id);
        }

/// <summary>
        /// 批量删除
        /// </summary>
        public void Delete(IOrganizationService service,EntityCollection ec)
        {
            if (ec != null && ec.Entities.Count > 0)
            {
               foreach(Entity en in ec.Entities)
               {
                   service.Delete(en.LogicalName, en.Id);
               }
            }
        }

/// <summary>
        /// 更新int类型的字段
        /// </summary>
        public void UpdateInt(IOrganizationService service, Entity en)
        {
            Entity updateEn = new Entity() { LogicalName = en.LogicalName,Id = en.Id };
            updateEn["new_int"] = 10;
            service.Update(updateEn);
        }

/// <summary>
        /// 更新string类型的字段
        /// </summary>
        public void UpdateInt(IOrganizationService service, Entity en)
        {
            Entity updateEn = new Entity() { LogicalName = en.LogicalName, Id = en.Id };
            updateEn["new_string"] = "abc";
            service.Update(updateEn);
        }

/// <summary>
        /// 更新float类型的字段
        /// </summary>
        public void UpdateFloat(IOrganizationService service, Entity en)
        {
            Entity updateEn = new Entity() { LogicalName = en.LogicalName, Id = en.Id };
            updateEn["new_float"] = 12.9;
            service.Update(updateEn);
        }

/// <summary>
        /// 更新Money类型的字段
        /// </summary>
        public void UpdateMoney(IOrganizationService service, Entity en)
        {
            Entity updateEn = new Entity() { LogicalName = en.LogicalName, Id = en.Id };
            updateEn["new_money"] = new Money(12);
            service.Update(updateEn);
        }

/// <summary>
        /// 更新OptionSetValue类型的字段
        /// </summary>
        public void UpdateOptionSetValue(IOrganizationService service, Entity en)
        {
            Entity updateEn = new Entity() { LogicalName = en.LogicalName, Id = en.Id };
            updateEn["new_optionsetvalue"] = new OptionSetValue(10);
            service.Update(updateEn);
        }

/// <summary>
        /// 更新EntityReference类型的字段
        /// </summary>
        public void UpdateEntityReference(IOrganizationService service, Entity en)
        {
            Entity updateEn = new Entity() { LogicalName = en.LogicalName, Id = en.Id };
            updateEn["new_account"] = new EntityReference() { LogicalName = "account",Id = Guid.NewGuid() };
            service.Update(updateEn);
        }
    }
}

这是改进后的模式:

/* 创建者:菜刀居士的博客
 * 创建日期:2014年07月06号
 */

namespace Net.CRM.OrganizationService
{
    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;

/// <summary>
    /// 高速开发---OrganizationService
    /// </summary>
    public class OrganizationServiceQuickDemo
    {
        /// <summary>
        /// 查询
        /// </summary>
        public Entity Retrieve(IOrganizationService service, Entity en)
        {
            return service.Retrieve(en,"new_int", "new_string");
        }

/// <summary>
        /// 删除
        /// </summary>
        public void Delete(IOrganizationService service, Entity en)
        {;
             service.Delete(en);
        }

/// <summary>
        /// 批量删除
        /// </summary>
        public void Delete(IOrganizationService service, EntityCollection ec)
        {
            service.Delete(ec);
        }

/// <summary>
        /// 更新int类型的字段
        /// </summary>
        public void UpdateInt(IOrganizationService service, Entity en)
        {
            service.Update(en, "new_int", 10);
        }

/// <summary>
        /// 更新string类型的字段
        /// </summary>
        public void UpdateInt(IOrganizationService service, Entity en)
        {
            service.Update(en, "new_string", "abc");
        }

/// <summary>
        /// 更新float类型的字段
        /// </summary>
        public void UpdateFloat(IOrganizationService service, Entity en)
        {
            service.Update(en, "new_float", 12.9); 
        }

/// <summary>
        /// 更新Money类型的字段
        /// </summary>
        public void UpdateMoney(IOrganizationService service, Entity en)
        {
            service.Update(en, "new_money", new Money(12)); 
        }

/// <summary>
        /// 更新OptionSetValue类型的字段
        /// </summary>
        public void UpdateOptionSetValue(IOrganizationService service, Entity en)
        {
            service.Update(en, "new_optionsetvalue", new OptionSetValue(10));
        }

/// <summary>
        /// 更新EntityReference类型的字段
        /// </summary>
        public void UpdateEntityReference(IOrganizationService service, Entity en)
        {
            service.Update(en, "new_account", new EntityReference() { LogicalName = "account", Id = Guid.NewGuid() });
        }
    }

/// <summary>
    /// 扩展方法
    /// </summary>
    public static class EntityFunction
    {
        public static Entity Retrieve(this IOrganizationService service, Entity en,params string[] attrs)
        {
            return service.Retrieve(en.LogicalName, en.Id, new ColumnSet(attrs));
        }

public static void Delete(this IOrganizationService service, Entity en)
        {
            service.Delete(en.LogicalName, en.Id);
        }

public static void Delete(this IOrganizationService service, EntityCollection ec)
        {
            if (ec != null && ec.Entities.Count > 0)
            {
                foreach (Entity en in ec.Entities)
                {
                    service.Delete(en.LogicalName, en.Id);
                }
            }
        }

public static void Update<T>(this IOrganizationService service, Entity en, string name, T value)
        {
            Entity updateEn = new Entity() { LogicalName = en.LogicalName,Id = en.Id };
            updateEn[name] = value;
            service.Update(updateEn);
        }
    }
}

是不是开发快非常多。

一般的,假设你的项目不是非常大,时间足够充分。这个时候就没有必要用高速开发了

当你的项目非常大或者功能非常多,时间非常紧,这个时候高速开发就非常有必要了。

crm高速开发之OrganizationService相关推荐

  1. crm高速开发之EntityCollection

    /* 创建者:菜刀居士的博客  * 创建日期:2014年07月07号  */ namespace Net.CRM.OrganizationService {     using System;     ...

  2. 视频教程-Python全栈9期(第八部分):CRM开发之curd组件和权限系统-Python

    Python全栈9期(第八部分):CRM开发之curd组件和权限系统 TriAquae开源运维软件创始人,混迹IT运维领域多年,曾就职于松下.国政通.飞信.中金.NOKIA等公司,维护过少至几十台,多 ...

  3. Python全栈9期(第八部分):CRM开发之curd组件和权限系统-李杰-专题视频课程

    Python全栈9期(第八部分):CRM开发之curd组件和权限系统-45人已学习 课程介绍         学到的不仅仅只是Python,还有培养编程思想! 2018年全套视频<Python全 ...

  4. JavaEE开发之SpringMVC中的自定义拦截器及异常处理

    上篇博客我们聊了<JavaEE开发之SpringMVC中的路由配置及参数传递详解>,本篇博客我们就聊一下自定义拦截器的实现.以及使用ModelAndView对象将Controller的值加 ...

  5. stm32 vscode 编译_STM32开发之 VSCode+gcc环境编译

    STM32开发之 VSCode+gcc环境编译 一.程序安装 1.VSCode:https://code.visualstudio.com/Download 好用到爆的文本编辑器,配合强大的插件,使你 ...

  6. 嵌入式开发之zynqMp ---Zynq UltraScale+ MPSoC 图像编码板zcu102

    嵌入式开发之zynqMp -Zynq UltraScale+ MPSoC 图像编码板zcu102 1.1 xilinx zynqMp 架构 1.1.1 16nm 级别工艺 Zynq UltraScal ...

  7. 智能路由器开发之OpenWrt简介

    智能路由器开发之OpenWrt简介 1. 引言 1.1 智能路由器的重要性和应用场景 智能路由器作为网络通信的核心设备,具有重要的地位和广泛的应用场景.传统的路由器主要提供基本的网络连接功能,但随着智 ...

  8. 镜像处理坐标 android,Android应用开发之Android重写ImageView实现图片镜像效果的代码教程...

    本文将带你了解Android应用开发之Android重写ImageView实现图片镜像效果的代码教程,希望本文对大家学Android有所帮助. 前两天朋友问我一个问题,如何实现从手机系统相册加载一张图 ...

  9. iOS开发之AVKit框架使用

    2019独角兽企业重金招聘Python工程师标准>>> iOS开发之AVKit框架使用 一.引言 在iOS开发框架中,AVKit是一个非常上层,偏应用的框架,它是基于AVFounda ...

  10. Android NDK开发之旅31 FFmpeg音频解码

    ###前言 #####基于Android NDK开发之旅30--FFmpeg视频播放这篇文章,我们已经学会视频解码基本过程.这篇文章就对音频解码进行分析. #####音频解码和视频解码的套路基本是一样 ...

最新文章

  1. PHP APM fiery 更新 v0.5.8.0
  2. Servlet WEB过滤器
  3. 从无到有写一个运维APP(二)
  4. 第一个,net core项目,.net core入门介绍来了
  5. leetcode209. 长度最小的子数组(滑动窗口)
  6. [css] 用css给一个元素加边框有哪些方法?
  7. 三星java3倍拍照手机_全世界拍照最强的两款手机,一个是三星,一个是它
  8. 错误记录(二)java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I错误时的原因及解决办法
  9. 字符集编码转换--MFC
  10. vue key重复_Vue 前端面试题
  11. There were no servers available to complete the specified operation
  12. 计算机设备如何巡检,计算机机房巡检管理制度
  13. ubuntu上vsftpd服务配置
  14. 自媒体/新媒体写作技巧
  15. 二、8【FPGA】Verilog中锁存器(Latch)原理、危害及避免
  16. SDM(Supervised Descent Method)代码实现在Windows下的配置与使用
  17. AD20/Altium designer——如何对线宽进行设置、布线过程中快速改线宽的方法
  18. 【主题词——百合花】
  19. Halcon 常用算子使用场合
  20. PrintSpool 服务经常自动停止!

热门文章

  1. 一起谈.NET技术,HTML5 - 搭建移动Web应用
  2. 光伏并网matlab,基于MATLAB的光伏并网设计
  3. Redis,唯快不破!
  4. Linux DRM KMS 驱动简介
  5. Oclint 安装指导
  6. linux 用户空间与内核空间——高端内存详解
  7. Linux 2.6 中的页面回收与反向映射
  8. 《System语言详解》——4. 探
  9. Android SD卡操作
  10. mysql ansi unicode_Ansi 与 Unicode 字符串类型的互相转换