In last article, I explained how to create early bound entity class and In this article, i am going to explain how to use the early bound entity classes for create,update and delete.
Create a New Entity Record Using the Early-bound Entity Classes and the Organization Service Context
OrganizationServiceContext orgContext =new OrganizationServiceContext(_serviceProxy);
Contact contact = new Contact()
{
FirstName = "Navish",
LastName = "Jain",
Address1_Line1 = "#1429",
Address1_City = "Chandigarh",
Address1_StateOrProvince = " Chandigarh ",
Address1_PostalCode = "160036",
Telephone1 = "123-234-5678"
};
orgContext.AddObject(contact);
orgContext.SaveChanges();
Update a New Entity Record Using the Early-bound Entity Classes and the Organization Service Context
var contact = orgContext .CreateQuery<Contact>().First(c => c.FirstName == "navish");
contact.JobTitle = "CRM Consultant";
orgContext .UpdateObject(contact);
orgContext .SaveChanges();
Delete a New Entity Record Using the Early-bound Entity Classes and the Organization Service Context
var contact = orgContext .CreateQuery<Contact>().First(c => c.FirstName == "navish");
orgContext .DeleteObject(contact);
orgContext .SaveChanges();
Create a New Entity Record Using the Early-Bound Entity Classes and without a Context Object
Contact contact = new Contact()
{
FirstName = "Navish",
LastName = "Jain",
Address1_Line1 = "#1429",
Address1_City = "Chandigarh",
Address1_StateOrProvince = " Chandigarh ",
Address1_PostalCode = "160036",
Telephone1 = "123-234-5678"
};
_contactId = _serviceProxy.Create(contact);
Create a New Entity Record Using the Early-bound Entity Classes and the Organization Service Context
OrganizationServiceContext orgContext =new OrganizationServiceContext(_serviceProxy);
Contact contact = new Contact()
{
FirstName = "Navish",
LastName = "Jain",
Address1_Line1 = "#1429",
Address1_City = "Chandigarh",
Address1_StateOrProvince = " Chandigarh ",
Address1_PostalCode = "160036",
Telephone1 = "123-234-5678"
};
orgContext.AddObject(contact);
orgContext.SaveChanges();
Update a New Entity Record Using the Early-bound Entity Classes and the Organization Service Context
var contact = orgContext .CreateQuery<Contact>().First(c => c.FirstName == "navish");
contact.JobTitle = "CRM Consultant";
orgContext .UpdateObject(contact);
orgContext .SaveChanges();
Delete a New Entity Record Using the Early-bound Entity Classes and the Organization Service Context
var contact = orgContext .CreateQuery<Contact>().First(c => c.FirstName == "navish");
orgContext .DeleteObject(contact);
orgContext .SaveChanges();
Create a New Entity Record Using the Early-Bound Entity Classes and without a Context Object
Contact contact = new Contact()
{
FirstName = "Navish",
LastName = "Jain",
Address1_Line1 = "#1429",
Address1_City = "Chandigarh",
Address1_StateOrProvince = " Chandigarh ",
Address1_PostalCode = "160036",
Telephone1 = "123-234-5678"
};
_contactId = _serviceProxy.Create(contact);
No comments:
Post a Comment
Note: only a member of this blog may post a comment.