这是主要的开发模式:

/* 创建者:菜刀居士的博客

 * 创建日期: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高速开发之QueryExpression

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

  2. crm高速开发之EntityCollection

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

  3. crm高速开发之Entity

    我们在后台代码里面操作Entity的时候,基本上是这样写的: /* 创建者:菜刀居士的博客  * 创建日期:2014年07月5号  */ namespace Net.CRM.Entity {     ...

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

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

  5. [Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘终结篇:UniLua热更新全然解读

    ---------------------------------------------------------------------------------------------------- ...

  6. 微信公众号开发之VS远程调试

    目录 (一)微信公众号开发之VS远程调试 (二)微信公众号开发之基础梳理 (三)微信公众号开发之自动消息回复和自定义菜单 前言 微信公众平台消息接口的工作原理大概可以这样理解:从用户端到公众号端一个流 ...

  7. Android混合开发之WebViewJavascriptBridge实现JS与java安全交互

    前言: 为了加快开发效率,目前公司一些功能使用H5开发,这里难免会用到Js与Java函数互相调用的问题,这个Android是提供了原生支持的,不过存在安全隐患,今天我们来学习一种安全方式来满足Js与j ...

  8. Android混合开发之WebView与Javascript交互

    前言: 最近公司的App为了加快开发效率选择了一部分功能采用H5开发,从目前市面的大部分App来讲,大致分成Native App.Web App.Hybrid App三种方式,个人觉得目前以Hybri ...

  9. UWP开发之Template10实践二:拍照功能你合理使用了吗?(TempState临时目录问题)

    最近在忙Asp.Net MVC开发一直没空更新UWP这块,不过有时间的话还是需要将自己的经验和大家分享下,以求共同进步. 在上章[UWP开发之Template10实践:本地文件与照相机文件操作的MVV ...

随机推荐

  1. HTML简单入门

    - Java攻城狮学习路线 - 基本结构 标准文档:www.w3.org <!DOCTYPE html> <html> <head> <meta charse ...

  2. 【转载】排名Top 16的Java实用类库

    *转载自HollisChuang 链接:http://www.hollischuang.com/archives/1606 1. org.apache.commons.io.IOUtils close ...

  3. avaScript中变量的声明和赋值

    变量是指程序中一个已经命名的存储单元,它的主要作用就是为数据操作提供存放信息的容器.变量是相对常量而言的.常量是一个不会改变的固定值,而变量的值可能会随着程序的执行而改变.变量有两个基本特征,即变量名 ...

  4. 用JSP实现动态交互

    一.什么是JSP? 1.在HTML中嵌入Java脚本代码 2.由应用服务器中的JSP引擎来编译和执行嵌入的Java脚本代码 3.然后将生成的整个页面信息返回给客户端   二.为什么需要基于B/S技术的 ...

  5. [Advanced Algorithm] - Validate US Telephone Numbers

    题目 如果传入字符串是一个有效的美国电话号码,则返回 true. 用户可以在表单中填入一个任意有效美国电话号码. 下面是一些有效号码的例子(还有下面测试时用到的一些变体写法): 555-555-555 ...

  6. kerberos认证原理---讲的非常细致,易懂

    前几天在给人解释Windows是如何通过Kerberos进行Authentication的时候,讲了半天也别把那位老兄讲明白,还差点把自己给绕进去.后来想想原因有以下两点:对于一个没有完全不了解Ker ...

  7. Arrays工具类的使用

    1.包: java.util 导包 2.此类包含用来操作数组(比如排序和搜索)的各种方法 特点: 该类中的方法都是静态方法,所以可以直接使用类名.方法名(实参)调用 3.查看成员方法: public ...

  8. js俄罗斯方块

    <html> <style>.c {margin :1px;width:19px;height:19px;background:red;position:absolute;} ...

  9. springboot:基础学习一 linux下后台启动springboot项目

    我们知道启动springboot的项目有三种方式: 运行主方法启动 使用命令 mvn spring-boot:run”在命令行启动该应用 运行“mvn package”进行打包时,会打包成一个可以直接 ...

  10. jsTree checkbox plugin使用笔记

    引入css文件 <link rel="stylesheet" type="text/css" href="js/assets/global/pl ...