crm高速开发之OrganizationService
这是主要的开发模式:
/* 创建者:菜刀居士的博客
* 创建日期: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的更多相关文章
- crm高速开发之QueryExpression
/* 创建者:菜刀居士的博客 * 创建日期:2014年07月06号 */ namespace Net.CRM.OrganizationService { using System; ...
- crm高速开发之EntityCollection
/* 创建者:菜刀居士的博客 * 创建日期:2014年07月07号 */ namespace Net.CRM.OrganizationService { using System; ...
- crm高速开发之Entity
我们在后台代码里面操作Entity的时候,基本上是这样写的: /* 创建者:菜刀居士的博客 * 创建日期:2014年07月5号 */ namespace Net.CRM.Entity { ...
- JavaEE开发之SpringMVC中的自定义拦截器及异常处理
上篇博客我们聊了<JavaEE开发之SpringMVC中的路由配置及参数传递详解>,本篇博客我们就聊一下自定义拦截器的实现.以及使用ModelAndView对象将Controller的值加 ...
- [Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘终结篇:UniLua热更新全然解读
---------------------------------------------------------------------------------------------------- ...
- 微信公众号开发之VS远程调试
目录 (一)微信公众号开发之VS远程调试 (二)微信公众号开发之基础梳理 (三)微信公众号开发之自动消息回复和自定义菜单 前言 微信公众平台消息接口的工作原理大概可以这样理解:从用户端到公众号端一个流 ...
- Android混合开发之WebViewJavascriptBridge实现JS与java安全交互
前言: 为了加快开发效率,目前公司一些功能使用H5开发,这里难免会用到Js与Java函数互相调用的问题,这个Android是提供了原生支持的,不过存在安全隐患,今天我们来学习一种安全方式来满足Js与j ...
- Android混合开发之WebView与Javascript交互
前言: 最近公司的App为了加快开发效率选择了一部分功能采用H5开发,从目前市面的大部分App来讲,大致分成Native App.Web App.Hybrid App三种方式,个人觉得目前以Hybri ...
- UWP开发之Template10实践二:拍照功能你合理使用了吗?(TempState临时目录问题)
最近在忙Asp.Net MVC开发一直没空更新UWP这块,不过有时间的话还是需要将自己的经验和大家分享下,以求共同进步. 在上章[UWP开发之Template10实践:本地文件与照相机文件操作的MVV ...
随机推荐
- CentOS6 在线安装PostgreSQL10
本文主要通过实际案例介绍如何在CentOS6环境中在线安装PostgreSQL10,安装环境需具备能够使用yum在线安装功能.具体安装步骤如下, 1 下载对应版本的PGDG文件 从https://yu ...
- 全文检索引擎及工具 Lucene Solr
全文检索引擎及工具 lucence lucence是一个全文检索引擎. lucence代码级别的使用步骤大致如下: 创建文档(org.apache.lucene.document.Document), ...
- easyui combobox的增加全选解决方案
1.解决方案背景: 项目中偶然需要用到easyui的combobox的组件,但是本组件自己没有包含全选的api事件.搜索了一些解决方案,但是不是很符合,后来发现是因为所使用的版本不一致所导致的.项 ...
- win2008系统日志不断出现【审核失败】
win2008系统日志不断出现[审核失败] [现象] 今天查看windows日志,在 -安全- 发现不断有消息刷出,显示 -审核失败- 事件ID为4624 的记录 每分钟大概刷新8条消息(如 ...
- Commons IO
Common IO 是一个工具库,用来帮助开发IO功能 它包括6个主要部分 Utility classes – 包括一些静态方法来执行常用任务 Input – InputStream 和 Reader ...
- 记录:通过SSH远程连接Ubuntu
一.安装openssh服务器 $ sudo apt-get install openssh-server 二.启动ssh服务 安装完成后,启动服务: $ sudo /etc/init.d/ssh st ...
- eas之数据融合
1.如何进行自由融合自由融合无须指定区域,KDTable将根据指定的融合模式,融合相邻且值相等的单元.// 自由行融合table.getMergeManager().setMergeMode(KDTM ...
- String使用方式详细总结
1.用双引号创建 2.用new String方式创建 3.双引号相加创建 4.两个new String相加时 5.两个引用相加时 6.双引号加new String创建或者new String加双引号创 ...
- 利用pandas库中的read_html方法快速抓取网页中常见的表格型数据
本文转载自:https://www.makcyun.top/web_scraping_withpython2.html 需要学习的地方: (1)read_html的用法 作用:快速获取在html中页面 ...
- apache+php连接数据库
######## 安装APACHE ##############安装apr/usr/src/apache+php/tar xf apr-1.5.2.tar.gzcd apr-1.5.2./config ...