当前位置: 首页>>代码示例>>C#>>正文


C# ISession.Insert方法代码示例

本文整理汇总了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 );
 }
开发者ID:phospher,项目名称:SchoolEndORM,代码行数:13,代码来源:Program.cs

示例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());
                }
            );
        }
开发者ID:stalinvr007,项目名称:VoDB,代码行数:17,代码来源:Session_Tests.cs

示例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);
                }
            );
        }
开发者ID:stalinvr007,项目名称:VoDB,代码行数:21,代码来源:Session_Tests.cs

示例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());
            });
        }
开发者ID:stalinvr007,项目名称:VoDB,代码行数:16,代码来源:Session_Tests.cs

示例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 }
                                     });
        }
开发者ID:Polylytics,项目名称:dashing,代码行数:77,代码来源:DatabaseInitializer.cs


注:本文中的ISession.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。