public static void Test_OneToManyInsert()
    {
      Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

      Nation nation = new Nation
                        {
                          code = "ROM",
                          name = "Romania",
                          capital = "Bucharest",
                          continent = "Europe",
                          Athletes = new List<AthleteOneToMany>()
                        };
      AthleteOneToMany athleteOneToMany = new AthleteOneToMany
                                            {
                                              name = "Lucian Bute",
                                              gender = "M",
                                              nation_code = "ROM",
                                              athlete_event = "Boxing",
                                            };

      ISessionFactory sessionFactory = cfg.BuildSessionFactory();
      using (ISession session = sessionFactory.OpenSession())
      {
        using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
        {
          nation.Athletes.Add(athleteOneToMany);
          session.Save(nation);
          tx.Commit();
        }
      }
      using (ISession session = sessionFactory.OpenSession())
      {
        IEnumerator<Nation> nations = session.Query<Nation>().Fetch(b => b.Athletes).GetEnumerator();
        while (nations.MoveNext())
        {
          if (nations.Current.code == "ROM")
            break;
        }
        List<object> nationValues = GetTableValues("nation", 216, new string[] { "code", "name", "capital", "continent" });
        List<object> athleteValues = GetTableValues("athlete", 6678, new string[] { "nation_code", "gender", "name", "event" });
        Debug.Assert(nations.Current.code == (string)nationValues[0]);
        Debug.Assert(nations.Current.name == (string)nationValues[1]);
        Debug.Assert(nations.Current.capital == (string)nationValues[2]);
        Debug.Assert(nations.Current.continent == (string)nationValues[3]);
        Debug.Assert(nations.Current.Athletes.Count == 1);
        Debug.Assert(nations.Current.Athletes[0].nation_code == (string)athleteValues[0]);
        Debug.Assert(nations.Current.Athletes[0].gender == (string)athleteValues[1]);
        Debug.Assert(nations.Current.Athletes[0].name == (string)athleteValues[2]);
        Debug.Assert(nations.Current.Athletes[0].athlete_event == (string)athleteValues[3]);
      }

      using (ISession session = sessionFactory.OpenSession())
      {
        //Delete a inserted information
        using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
        {
          session.Delete(nation);
          trans.Commit();
        }
      }
    }
Beispiel #2
0
        public static void Test_OneToManyInsert()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

            Nation nation = new Nation
            {
                code      = "ROM",
                name      = "Romania",
                capital   = "Bucharest",
                continent = "Europe",
                Athletes  = new List <AthleteOneToMany>()
            };
            AthleteOneToMany athleteOneToMany = new AthleteOneToMany
            {
                name          = "Lucian Bute",
                gender        = "M",
                nation_code   = "ROM",
                athlete_event = "Boxing",
            };

            ISessionFactory sessionFactory = cfg.BuildSessionFactory();

            using (ISession session = sessionFactory.OpenSession())
            {
                using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    nation.Athletes.Add(athleteOneToMany);
                    session.Save(nation);
                    tx.Commit();
                }
            }
            using (ISession session = sessionFactory.OpenSession())
            {
                IEnumerator <Nation> nations = session.Query <Nation>().Fetch(b => b.Athletes).GetEnumerator();
                while (nations.MoveNext())
                {
                    if (nations.Current.code == "ROM")
                    {
                        break;
                    }
                }
                List <object> nationValues  = GetTableValues("nation", 216, new string[] { "code", "name", "capital", "continent" });
                List <object> athleteValues = GetTableValues("athlete", 6678, new string[] { "nation_code", "gender", "name", "event" });
                Debug.Assert(nations.Current.code == (string)nationValues[0]);
                Debug.Assert(nations.Current.name == (string)nationValues[1]);
                Debug.Assert(nations.Current.capital == (string)nationValues[2]);
                Debug.Assert(nations.Current.continent == (string)nationValues[3]);
                Debug.Assert(nations.Current.Athletes.Count == 1);
                Debug.Assert(nations.Current.Athletes[0].nation_code == (string)athleteValues[0]);
                Debug.Assert(nations.Current.Athletes[0].gender == (string)athleteValues[1]);
                Debug.Assert(nations.Current.Athletes[0].name == (string)athleteValues[2]);
                Debug.Assert(nations.Current.Athletes[0].athlete_event == (string)athleteValues[3]);
            }

            using (ISession session = sessionFactory.OpenSession())
            {
                //Delete a inserted information
                using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    session.Delete(nation);
                    trans.Commit();
                }
            }
        }
    public static void Test_OneToManyDelete()
    {
      Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

      ISessionFactory sessionFactory = cfg.BuildSessionFactory();
      using (ISession session = sessionFactory.OpenSession())
      {
        IEnumerator<Nation> nations = session.Query<Nation>().Fetch(b => b.Athletes).GetEnumerator();
        int count = 0;
        while (nations.MoveNext())
        {
          count++;
        }
        Debug.Assert(count == 215);
      }

      Nation nation = new Nation
                        {
                          code = "ROM",
                          name = "Romania",
                          capital = "Bucharest",
                          continent = "Europe",
                          Athletes = new List<AthleteOneToMany>()
                        };
      AthleteOneToMany athleteOneToMany = new AthleteOneToMany
                                            {
                                              name = "Lucian Bute",
                                              gender = "M",
                                              nation_code = "ROM",
                                              athlete_event = "Boxing",
                                            };
      nation.Athletes.Add(athleteOneToMany);
      using (ISession session = sessionFactory.OpenSession())
      {
        using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
        {
          session.Save(nation);
          tx.Commit();
        }
      }

      using (ISession session = sessionFactory.OpenSession())
      {
        IEnumerator<Nation> nations = session.Query<Nation>().Fetch(b => b.Athletes).GetEnumerator();
        int count = 0;
        while (nations.MoveNext())
        {
          count++;
        }
        Debug.Assert(count == 216);
      }

      using (ISession session = sessionFactory.OpenSession())
      {
        //Delete a inserted information
        using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
        {
          session.Delete(nation);
          trans.Commit();
        }
      }

      using (ISession session = sessionFactory.OpenSession())
      {
        IEnumerator<Nation> nations = session.Query<Nation>().Fetch(b => b.Athletes).GetEnumerator();
        int count = 0;
        while (nations.MoveNext())
        {
          count++;
        }
        Debug.Assert(count == 215);
      }
    }
Beispiel #4
0
        public static void Test_OneToManyDelete()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

            ISessionFactory sessionFactory = cfg.BuildSessionFactory();

            using (ISession session = sessionFactory.OpenSession())
            {
                IEnumerator <Nation> nations = session.Query <Nation>().Fetch(b => b.Athletes).GetEnumerator();
                int count = 0;
                while (nations.MoveNext())
                {
                    count++;
                }
                Debug.Assert(count == 215);
            }

            Nation nation = new Nation
            {
                code      = "ROM",
                name      = "Romania",
                capital   = "Bucharest",
                continent = "Europe",
                Athletes  = new List <AthleteOneToMany>()
            };
            AthleteOneToMany athleteOneToMany = new AthleteOneToMany
            {
                name          = "Lucian Bute",
                gender        = "M",
                nation_code   = "ROM",
                athlete_event = "Boxing",
            };

            nation.Athletes.Add(athleteOneToMany);
            using (ISession session = sessionFactory.OpenSession())
            {
                using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    session.Save(nation);
                    tx.Commit();
                }
            }

            using (ISession session = sessionFactory.OpenSession())
            {
                IEnumerator <Nation> nations = session.Query <Nation>().Fetch(b => b.Athletes).GetEnumerator();
                int count = 0;
                while (nations.MoveNext())
                {
                    count++;
                }
                Debug.Assert(count == 216);
            }

            using (ISession session = sessionFactory.OpenSession())
            {
                //Delete a inserted information
                using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    session.Delete(nation);
                    trans.Commit();
                }
            }

            using (ISession session = sessionFactory.OpenSession())
            {
                IEnumerator <Nation> nations = session.Query <Nation>().Fetch(b => b.Athletes).GetEnumerator();
                int count = 0;
                while (nations.MoveNext())
                {
                    count++;
                }
                Debug.Assert(count == 215);
            }
        }