예제 #1
0
 public void TestCache()
 {
     NHibernateProfiler.Initialize();
     var groupNames = new[] {"a1", "b1", "c1"};
     using (var session = SessionFactory.OpenSession())
     using (var tx = session.BeginTransaction())
     {
         session.CreateSQLQuery("delete from dbo.Registrations;delete from dbo.[Group]")
             .ExecuteUpdate();
         session.CreateSQLQuery("delete from dbo.[User]");
         groupNames.ForEach(x =>
         {
             var group = new Group {Id = Guid.NewGuid(), Name = x, Date = DateTime.UtcNow};
             session.Save(group);
         });
         tx.Commit();
     }
     using (var session = SessionFactory.OpenSession())
     using (var tx = session.BeginTransaction())
     {
         var user = new User {Name = "User1", Id = Guid.NewGuid(), Date = DateTime.UtcNow};
         session.Save(user);
         tx.Commit();
     }
     using (var session = SessionFactory.OpenSession())
     using (var tx = session.BeginTransaction())
     {
         var user = session.Query<User>().First();
         var groups = GetGroups(session);
         var group = groups.First();
         var registration = new GroupRegistration
         {
             Id = Guid.NewGuid(),
             User = user,
             Group = group,
             Date = DateTime.UtcNow
         };
         user.Registrations.Add(registration);
         group.Registrations.Add(registration);
         session.Save(registration);
         session.Flush();
         tx.Commit();
     }
     using (var session = SessionFactory.OpenSession())
     {
         var g = GetGroups(session);
     }
     using (var session = SessionFactory.OpenSession())
     {
         var g = GetGroups(session);
     }
 }
예제 #2
0
        public void TestCreate()
        {
            HelloContext helloContext = new HelloContext();

            User user = new User();
            user.Nombre = "Nico";

            Movement movement = new Movement();
            movement.CreationTime = DateTime.Now;

            user.Movements.Add(movement);

            helloContext.Users.Add(user);

            helloContext.SaveChanges();
        }