本文整理汇总了C#中ISession.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.Insert方法的具体用法?C# ISession.Insert怎么用?C# ISession.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.Insert方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestInsert
private static void TestInsert( ISession session )
{
Student student = new Student ();
Console.WriteLine ( "Insert an object to database..." );
student.StudentId = "200730740404";
student.Name = "Dickson";
student.Gender = "Male";
session.Insert ( student );
session.Submit ();
Console.WriteLine ( "Inserted Successfully..." );
Console.ReadKey ();
ReadObjects ( session );
}
示例2: Session_Delete_Employee
public void Session_Delete_Employee(ISession session)
{
session.WithRollback(s =>
{
var count = session.GetAll<Employee>().Count();
var sergio = session.Insert(new Employee
{
FirstName = "Sérgio",
LastName = "Ferreira"
});
session.Delete(sergio);
Assert.AreEqual(count, session.GetAll<Employee>().Count());
}
);
}
示例3: Session_Update_Employee
public void Session_Update_Employee(ISession session)
{
session.WithRollback(s =>
{
var sergio = session.Insert(new Employee
{
FirstName = "Sérgio",
LastName = "Ferreira"
});
sergio.FirstName = "Alien";
session.Update(sergio);
var alien = session.GetById(sergio);
Assert.That(alien, Is.Not.Null);
Assert.AreEqual("Alien", alien.FirstName);
}
);
}
示例4: Session_Insert_Employee
public void Session_Insert_Employee(ISession session)
{
session.WithRollback(s =>
{
var count = session.GetAll<Employee>().Count();
var employee = session
.Insert(new Employee
{
FirstName = "Sérgio",
LastName = "Ferreira"
});
Assert.IsNotNull(employee);
Assert.AreEqual(count + 1, session.GetAll<Employee>().Count());
});
}
示例5: InsertData
private void InsertData(ISession session) {
var users = new List<User>();
for (var i = 0; i < 10; i++) {
var user = new User { Username = "User_" + i };
users.Add(user);
session.Insert(user);
}
var blogs = new List<Blog>();
for (var i = 0; i < 10; i++) {
var blog = new Blog { Title = "Blog_" + i };
blogs.Add(blog);
session.Insert(blog);
}
var posts = new List<Post>();
for (var i = 0; i < 20; i++) {
var userId = i / 2;
var blogId = i / 2;
var post = new Post { Author = users[userId], Blog = blogs[blogId], Title = "Post_" + i };
session.Insert(post);
posts.Add(post);
}
for (var i = 0; i < 30; i++) {
var comment = new Comment { Post = posts[i / 2], User = users[i / 3], Content = "Comment_" + i };
session.Insert(comment);
}
var tags = new List<Tag>();
for (var i = 0; i < 20; i++) {
var tag = new Tag { Content = "Tag_" + i };
tags.Add(tag);
session.Insert(tag);
}
for (var i = 0; i < 30; i++) {
var postTag = new PostTag { Post = posts[i / 2], Tag = tags[i / 2] };
session.Insert(postTag);
}
// insert single comment with null User to check that nulls are returned properly
var nullUserComment = new Comment { Post = posts[0], User = null, Content = "Nullable User Content" };
session.Insert(nullUserComment);
var nullTag = new Tag { Content = "Null Post Tag" };
session.Insert(nullTag);
var nullPostTag = new PostTag { Tag = nullTag };
session.Insert(nullPostTag);
// add user for bulk update
session.Insert(new User { Username = "BulkUpdate", Password = "Blah" });
// add users for bulk delete
session.Insert(new User { Username = "BulkDelete", Password = "Foo" }, new User { Username = "BulkDelete", Password = "Bar" });
// test delete user
session.Insert(new User { Username = "TestDelete", Password = "Blah" });
// test empty collection
session.Insert(new Blog { Title = "EmptyBlog" });
// multiple fetch many stuff
session.Insert(new Questionnaire { Name = "Foo" });
session.Insert(new Question { Questionnaire = new Questionnaire { QuestionnaireId = 1 }, Name = "Bar" });
session.Insert(new Booking());
session.Insert(new Room { Name = "Room 1" });
session.Insert(new RoomSlot { Room = new Room { RoomId = 1 } });
session.Insert(new Bed { RoomSlot = new RoomSlot { RoomSlotId = 1 }, Booking = new Booking { BookingId = 1 } });
session.Insert(
new QuestionnaireResponse { Booking = new Booking { BookingId = 1 }, Questionnaire = new Questionnaire { QuestionnaireId = 1 } });
session.Insert(
new QuestionResponse {
Question = new Question { QuestionId = 1 },
QuestionnaireResponse = new QuestionnaireResponse { QuestionnaireResponseId = 1 }
});
}