This repository was archived by the owner on Oct 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
UseOnceTo
Daniel Wertheim edited this page Nov 29, 2012
·
3 revisions
UseOnceTo() is just a convenience method that you can use. It lets you get rid of the code necessary for creating a Session via the factory method of the Database.
db.UseOnceTo().Insert(customer);var customers = db.UseOnceTo().Query<Customer>().Where(c => c.Points > 10000).ToList();You should only use these methods if you are doing ONE Read or Write operation. If you do several in a row, YOU SHOULD CREATE A SPECIFIC INSTANCE OF Session. The reason for this is that UseOnceTo() encapsulate the creation of a session under the hood. And since each of this opens connections to the database, you could affect performance if you call UseOnceTo() repeatedly.
You can also make use of db.WithSession():
db.WithSession(s => s.Insert(customer));var customers = db.WithSession(s =>
s.Query<Customer>().Where(c => c.Points > 10000).ToList());