LINQ Inserts
The following example illustrates inserting a record using LINQ.
using System.Linq;
using System.Data.EntityClient;
using System.Data.RSSBus.Facebook;
//...
Entities context = new Entities();
Statuses newRecord = new Statuses {
Message = "Sample status message"
};
context.Statuses.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