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(dynamic 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, Etag etag);
Third overload stores entity in session with given id.
void Store(dynamic 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
// when database is new and empty database and conventions are not changed: 'employee/1'
session.Store(new Employee
{
FirstName = "John",
LastName = "Doe"
});
// send all pending operations to server, in this case only `Put` operation
session.SaveChanges();