Session: Storing Entities
To store entities inside the session object, use one of the three Store
methods.
Syntax
First overload: Stores the entity in a session, then extracts the ID from the entity or generates a new one if it's not available.
void Store(object entity);
Second overload: Stores the entity in a session with given ID.
void Store(object entity, string id);
Third overload: Stores the entity in a session with given ID, forces concurrency check with given change vector.
void Store(object entity, string changeVector, string id);
Parameters | ||
---|---|---|
entity | object | Entity that will be stored |
changeVector | string | Entity changeVector, used for concurrency checks (null to skip check) |
id | string | Entity will be stored under this ID, (null to generate automatically) |
Example
// generate Id automatically
session.Store(new Employee
{
FirstName = "John",
LastName = "Doe"
});
// send all pending operations to server, in this case only `Put` operation
session.SaveChanges();