LINQ Inserts
The following example illustrates inserting a record using LINQ.
using System.Linq;
using System.Data.EntityClient;
using System.Data.RSSBus.SimpleDB;
//...
Entities context = new Entities();
Lead newRecord = new Lead {
FullName = "The Joker"
};
context.Leads.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.
You can do so by reading the Id from the record after it has been saved. The database generated Id
will be assigned to the saved record.
newRecord.Id