Session: Storing entities in session
To store entities inside session object use one of the four Store
methods.
Syntax
First overload stores entity in session, extracts Id from entity using Conventions
or generates new one if it is not available.
void Store(object entity);
Second overload stores entity in session, extracts Id from entity using Conventions
or generates new one if it is not available and forces concurrency check with given Etag.
void Store(object entity, string changeVector, string id);
Third overload stores entity in session with given id.
void Store(object entity, string id);
Fourth overload stores entity in session with given id and forces concurrency check with given Etag.
void Store(object entity, Etag etag, string id);
Parameters | ||
---|---|---|
entity | object | Entity that will be stored |
etag | Etag | Current entity etag, used for concurrency checks (null to skip check) |
id | string | Entity will be stored under this key, (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();