Organizationservice for rapid CRM Development

Source: Internet
Author: User

This is the basic development mode:

/* Creator: the blog of caidao jushi
* Creation date: January 1, July 06, 2014
*/

Namespace net. CRM. organizationservice
{
Using system;
Using Microsoft. xrm. SDK;
Using Microsoft. xrm. SDK. query;

/// <Summary>
/// Basic mode --- organizationservice
/// </Summary>
Public class organizationservicedemo
{
/// <Summary>
/// Query
/// </Summary>
Public Entity retrieve (iorganizationservice service, entity en)
{
Return service. Retrieve (EN. logicalname, en. ID, new columnset ("new_int", "new_string "));
}

/// <Summary>
/// Delete
/// </Summary>
Public void Delete (iorganizationservice service, entity en)
{
Service. Delete (EN. logicalname, en. ID );
}

/// <Summary>
/// Batch Delete
/// </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>
/// Update fields of the int type
/// </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>
/// Update a string field
/// </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>
/// Update a float Field
/// </Summary>
Public void updatefloat (iorganizationservice service, entity en)
{
Entity updateen = new entity () {logicalname = en. logicalname, id = en. ID };
Updateen ["maid"] = 12.9;
Service. Update (updateen );
}

/// <Summary>
/// Update the money Field
/// </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>
/// Update fields of the optionsetvalue type
/// </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>
/// Update fields of the entityreference type
/// </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 );
}
}
}

 

 

This is the improved mode:

 

/* Creator: the blog of caidao jushi
* Creation date: January 1, July 06, 2014
*/

Namespace net. CRM. organizationservice
{
Using system;
Using Microsoft. xrm. SDK;
Using Microsoft. xrm. SDK. query;

/// <Summary>
/// Quick development --- organizationservice
/// </Summary>
Public class organizationservicequickdemo
{
/// <Summary>
/// Query
/// </Summary>
Public Entity retrieve (iorganizationservice service, entity en)
{
Return service. Retrieve (EN, "new_int", "new_string ");
}

/// <Summary>
/// Delete
/// </Summary>
Public void Delete (iorganizationservice service, entity en)
{;
Service. Delete (en );
}

/// <Summary>
/// Batch Delete
/// </Summary>
Public void Delete (iorganizationservice service, entitycollection EC)
{
Service. Delete (EC );
}

/// <Summary>
/// Update fields of the int type
/// </Summary>
Public void updateint (iorganizationservice service, entity en)
{
Service. Update (EN, "new_int", 10 );
}

/// <Summary>
/// Update a string field
/// </Summary>
Public void updateint (iorganizationservice service, entity en)
{
Service. Update (EN, "new_string", "ABC ");
}

/// <Summary>
/// Update a float Field
/// </Summary>
Public void updatefloat (iorganizationservice service, entity en)
{
Service. Update (EN, "new_float", 12.9 );
}

/// <Summary>
/// Update the money Field
/// </Summary>
Public void updatemoney (iorganizationservice service, entity en)
{
Service. Update (EN, "new_money", new money (12 ));
}

/// <Summary>
/// Update fields of the optionsetvalue type
/// </Summary>
Public void updateoptionsetvalue (iorganizationservice service, entity en)
{
Service. Update (EN, "new_optionsetvalue", new optionsetvalue (10 ));
}

/// <Summary>
/// Update fields of the entityreference type
/// </Summary>
Public void updateentityreference (iorganizationservice service, entity en)
{
Service. Update (EN, "new_account", new entityreference () {logicalname = "Account", id = guid. newguid ()});
}
}

/// <Summary>
/// Extension Method
/// </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 );
}
}
}

Is development much faster.

 

Generally, if your project is not large enough time. At this time, there is no need to use quick development.

When your project is large, has many functions, and has a tight schedule, quick development is necessary.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.