本文整理汇总了C#中ISession.Save方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.Save方法的具体用法?C# ISession.Save怎么用?C# ISession.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute(ISession session, long taskId, DateTime sentDate)
{
bool closeSession = false;
if (session == null)
{
session = _businessSafeSessionManager.Session;
closeSession = true;
}
var systemUser = session.Load<UserForAuditing>(SystemUser.Id);
var taskDueTomorrowEscalation = new EscalationTaskDueTomorrow()
{
TaskId = taskId,
TaskDueTomorrowEmailSentDate = sentDate,
CreatedBy = systemUser,
CreatedOn = DateTime.Now
};
session.Save(taskDueTomorrowEscalation);
//Log4NetHelper.Log.Debug("Saved EscalationTaskDueTomorrow sent indicator");
if (closeSession)
{
session.Close();
}
}
示例2: TestInit
public void TestInit()
{
AutomapperConfig.CreateMapping();
this.lanes = new List<Lane>();
this.timeSlots = new List<TimeSlot>();
DependencyResolverInitializer.Initialize();
this._configuration = ServiceLocator.Current.GetInstance<Configuration>();
this._sessionFactory = LocalSessionInitializer.Initialize();
this._session = this._sessionFactory.GetCurrentSession();
new SchemaExport(_configuration).Execute(true, true, false);
// add some lanes and timeslots to the database
// there are timeslots from 1000 hours => 2300 hours
for (int i = 0; i < 10; i++)
{
var timeSlot = new TimeSlot() { Start = TimeSpan.FromHours(10 + i), End = TimeSpan.FromHours(11 + i) };
this.timeSlots.Add(timeSlot);
_session.Save(timeSlot);
var lane = new Lane() { Name = (i + 1).ToString() };
this.lanes.Add(lane);
_session.Save(lane);
}
}
示例3: QueryUsingReadonlyProperty
public void QueryUsingReadonlyProperty()
{
using (session = OpenSession())
{
Nums nums1 = new Nums {ID = 1, NumA = 1, NumB = 2};
session.Save(nums1);
Nums nums2 = new Nums {ID = 2, NumA = 2, NumB = 2 };
session.Save(nums2);
Nums nums3 = new Nums {ID = 3, NumA = 5, NumB = 2 };
session.Save(nums3);
session.Flush();
session.Clear();
var nums = session.CreateQuery("from Nums b where b.Sum > 4").List<Nums>();
Assert.That(nums.Count, Is.EqualTo(1));
Assert.That(nums[0].Sum, Is.EqualTo(7));
session.Delete("from Nums");
session.Flush();
session.Close();
}
}
示例4: SelectWithWhereClause
public void SelectWithWhereClause()
{
using (session = OpenSession())
{
User user1 = new User();
user1.UserName = "User1";
session.Save(user1);
User user2 = new User();
user2.UserName = "User2";
session.Save(user2);
BlogPost post = new BlogPost();
post.Title = "Post 1";
post.Poster = user1;
session.Save(post);
session.Flush();
session.Clear();
User poster = (User) session.Get(typeof (User), user1.ID);
string hql = "from BlogPost b where b.Poster = :poster";
IList list = session.CreateQuery(hql).SetParameter("poster", poster).List();
Assert.AreEqual(1, list.Count);
BlogPost retrievedPost = (BlogPost) list[0];
Assert.AreEqual(post.ID, retrievedPost.ID);
Assert.AreEqual(user1.ID, retrievedPost.Poster.ID);
session.Delete("from BlogPost");
session.Delete("from User");
session.Flush();
session.Close();
}
}
示例5: PopulateData
private void PopulateData(ISession s)
{
for (var i = 0; i < 2; i++)
{
var p = new HierarchyModel
{
Hid = string.Format("/{0}/", i + 1),
Name = string.Format("Parent {0}", i + 1)
};
s.Save(p);
var childs = new List<string>();
for (var j = 0; j < 10; j++)
{
var c = new HierarchyModel
{
Hid = string.Format("/{0}/{1}/", i + 1, j + 1),
Name = string.Format("Child {0}/{1}", i + 1, j + 1)
};
childs.Add(c.Hid);
s.Save(c);
}
Items.Add(p.Hid, childs);
}
}
示例6: SetupData
public static void SetupData(ISession session)
{
using (ITransaction transaction = session.BeginTransaction())
{
var user = new User() { Username = "user" };
session.Save(user);
for (int i = 0; i < 10; i++)
{
var blog = new Blog() { Name = String.Format("Blog{0}", i), User = user };
var category1 = new Category() { Blog = blog, Description = "Description1", HtmlUrl = "htmlurl1", RssUrl = "rssurl1" };
var category2 = new Category() { Blog = blog, Description = "Description2", HtmlUrl = "htmlurl2", RssUrl = "rssurl2" };
var category3 = new Category() { Blog = blog, Description = "Description3", HtmlUrl = "htmlurl3", RssUrl = "rssurl3" };
blog.AddCategory(category1);
blog.AddCategory(category2);
blog.AddCategory(category3);
session.Save(blog);
for (int j = 0; j < 1000; j++)
{
var post = new Post() { Date = DateTime.Now, Title = String.Format("Blog{0}Post{1}", i, j) };
post.Blog = blog;
session.Save(post);
}
}
transaction.Commit();
}
}
示例7: CreateVoyages
public static void CreateVoyages(ISession session)
{
session.Save(V100);
session.Save(V200);
session.Save(V300);
session.Save(V400);
}
示例8: SetUpEachTest
public void SetUpEachTest()
{
new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Execute(false, true, false, false);
parent = new CompositeIdParent();
child1 = new CompositeIdChild();
child1.Parent = parent;
child1.CompositeIdPart1 = "child1key1";
child1.CompositeIdPart2 = "child1key2";
child2 = new CompositeIdChild();
child1.Parent = parent;
child2.CompositeIdPart1 = "child2key1";
child2.CompositeIdPart2 = "child2key2";
session = sf.OpenSession();
ITransaction tx = session.BeginTransaction();
session.Save(parent);
session.Save(child1);
session.Save(child2);
tx.Commit();
session.Close();
}
示例9: CreateCustomers
public static void CreateCustomers(ISession session)
{
session.Save(C1);
session.Save(new CustomerAgreement(C1, new FastestRoutingPolicy()));
session.Save(C2);
session.Save(new CustomerAgreement(C2, new CheapestRoutingPolicy()));
}
示例10: OnSetUp
protected override void OnSetUp()
{
session = sessions.OpenSession();
session.Save(new County("aaaa", "AA", Wkt.Read("POLYGON((1 0, 2 0, 2 1, 1 1, 1 0))")));
session.Save(new County("bbbb", "BB", Wkt.Read("POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))")));
session.Save(new County("cccc", "BB", Wkt.Read("POLYGON((2 1, 3 1, 3 2, 2 2, 2 1))")));
session.Save(new County("dddd", "AA", Wkt.Read("POLYGON((2 0, 3 0, 3 1, 2 1, 2 0))")));
session.Flush();
}
示例11: SaveChildObjects
private static void SaveChildObjects(ISession dataSession, Category category)
{
category.SearchResultLinks.ForEach(r => dataSession.Save(r));
category.SubCategories.ForEach(r =>
{
r.SubCategories.ForEach(s => dataSession.Save(s));
r.SearchResultLinks.ForEach(s => dataSession.Save(s));
dataSession.Save(r);
});
dataSession.Save(category);
}
示例12: OnSetUp
protected override void OnSetUp()
{
session = sessions.OpenSession();
session.Save(new Simple("a point", new Point(12, 45)));
session.Save(new Simple("a null", null));
session.Save(new Simple("a collection empty 1", Wkt.Read("GEOMETRYCOLLECTION EMPTY")));
session.Save(new Simple("a collection empty 2", GeometryCollection.Empty));
session.Flush();
}
示例13: FillDb
private static Continent FillDb(ISession s)
{
Continent europe = new Continent();
europe.Name="Europe";
Country france = new Country();
france.Name="France";
europe.Countries=new IESI.HashedSet<Country>();
europe.Countries.Add(france);
s.Save(france);
s.Save(europe);
return europe;
}
示例14: Create
public static void Create(ISession session)
{
var customers = Using.TheseConventions()
.With<Customer>(options => options.Length(customer => customer.Name, 5, 100))
.With<Customer>(options => options.Range(customer => customer.DiscountPercentage, 0, 25))
.ForEach<Customer>(customer => session.Save(customer))
.Many<Customer>(20, 40)
.ToArray();
var managers = EmployeeGenerator(session)
.Many<Employee>(2);
var employees = EmployeeGenerator(session)
.ForEach<Employee>(employee => Maybe.Do(() => managers.PickOne().AddSubordinate(employee)))
.Many<Employee>(20)
.ToArray();
var suppliers = Using.TheseConventions()
.With<Supplier>(options => options.Length(supplier => supplier.Website, 1, 100))
.With<Supplier>(options => options.Length(supplier => supplier.Name, 5, 25))
.ForEach<Supplier>(supplier => session.Save(supplier))
.Many<Supplier>(20)
.ToArray();
var products = Using.TheseConventions()
.ForEach<ProductSource>(productsource => session.Save(productsource))
.With<Product>(options => options.Ignore(product => product.Version))
.With<Product>(options => options.For(
product => product.Category,
ProductCategory.Beverages,
ProductCategory.Condiments,
ProductCategory.DairyProducts,
ProductCategory.Produce))
.With<Product>(g => g.Method<double>(0, 5, (product, d) => product.AddSource(suppliers.PickOne(), d)))
.With<Product>(options => options.Length(product => product.Name, 1, 50))
.ForEach<Product>(product => session.Save(product))
.Many<Product>(50)
.ToArray();
Using.TheseConventions()
.With<OrderItem>(options => options.For(item => item.Product, products))
.OneToMany<Order, OrderItem>(1, 5, (order, item) => order.AddItem(item))
.With<Order>(options => options.For(order => order.Customer, customers))
.With<Order>(options => options.For(order => order.Employee, employees))
.OneToOne<Order, Address>((order, address) => order.DeliveryAddress = address)
.ForEach<Order>(order => session.Save(order))
.Many<Order>(50);
session.Flush();
}
示例15: Setup
public void Setup() {
session = CreateSchemaAndSession();
using (var tx = session.BeginTransaction()) {
kunde1 = new Kunde("K1", new Adresse("S1", "P1", "O1"));
session.Save(kunde1);
kunde2 = new Kunde("K2", new Adresse("S2", "P2", "O2"));
session.Save(kunde2);
var position = new Position("B1", 1);
session.Save(position);
auftrag1 = new Auftrag(kunde1, DateTime.Parse("01.01.2010"), position);
session.Save(auftrag1);
position = new Position("B2", 1);
session.Save(position);
auftrag2 = new Auftrag(kunde2, DateTime.Parse("02.02.2010"), position);
session.Save(auftrag2);
position = new Position("B3", 1);
session.Save(position);
auftrag3 = new Auftrag(kunde1, DateTime.Parse("03.03.2010"), position);
session.Save(auftrag3);
tx.Commit();
}
sut = new AuftragRepository(session);
}