LINQ Inserts
The following example illustrates inserting a record using LINQ.
using System.Linq;
using System.Data.EntityClient;
using System.Data.RSSBus.SalesForce;
//...
Entities context = new Entities();
Account newRecord = new Account {
Name = "Floppy Disks"
};
context.Accounts.AddObject(newRecord);
try {
context.SaveChanges();
} catch (Exception e) {
Console.WriteLine(e);
}
It is often useful to retrieve the result of the insert command to, say, obtain the new record's Id. Here is the code
necessary to retrieve the Id of a newly inserted record:
var conn = (context.Connection as EntityConnection).StoreConnection as SalesForceConnection; Hashtable result = conn.GetLastResult(); String Id = result["id"];