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);
}
}
}
是不是开发快非常多。
一般的,假设你的项目不是非常大,时间足够充分。这个时候就没有必要用高速开发了
当你的项目非常大或者功能非常多,时间非常紧,这个时候高速开发就非常有必要了。
最新文章
- 构建hibernate
- shell的一些应用场景
- dispay属性的block,inline,inline-block
- 登陆mysql时提示异常的解决方法
- Python语言开发的一些问题
- WCF服务编程中使用SvcMap实现类型共享等技巧【转】
- sql的存储过程调用
- 一周一话题之四(JavaScript、Dom、jQuery全面复习总结<;Dom篇>;)
- codeforces C. Booking System
- leetcode修炼之路——350. Intersection of Two Arrays II
- Junit 测试常见错误
- 详细领悟ThreadLocal变量
- maven项目生成war包
- setBit testBit权限管理(shiro项目中来的二)
- CyQ.data MDataTable
- Python excel 奇怪的通信规则
- 利用StackExchange.Redis和Log4Net构建日志队列
- git@github.com: Permission denied (publickey).////remote: Permission to xxx/test.git denied to xxx.等权限问题
- Python支付宝在线支付API
- JavaScript中的获取元素的方法
热门文章
- C99C新增内容
- [转载]Android平台第三方应用分享到微信开发
- Asp.net MVC Checkbox控件 和 Nullable<;bool>;, 或bool?类型
- AI不与人为敌
- Content-Encoding值
- webpack学习(五)—webpack+react+es6(第1篇)
- LOJ #6041. 「雅礼集训 2017 Day7」事情的相似度 LCT+SAM+线段树
- BZOJ 1426: 收集邮票 数学期望 + DP
- eas之执行sql的方式
- BOS工具之BOS应用框架