public static void Test_ManyToManySelect() { Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly); using (CUBRIDConnection con = TestCases.GetDemodbConnection()) { TestCases.ExecuteSQL("drop table if exists AthleteEvent", con); TestCases.ExecuteSQL("create table AthleteEvent (event_code int, athlete_code int, primary key(event_code,athlete_code))", con); TestCases.ExecuteSQL("insert into AthleteEvent values(20038, 10011)", con); TestCases.ExecuteSQL("insert into AthleteEvent values(20038, 14313)", con); ISessionFactory sessionFactory = cfg.BuildSessionFactory(); using (ISession session = sessionFactory.OpenSession()) { IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator(); while (athletes.MoveNext()) { if (athletes.Current.Events.Count != 0) { List <object> eventValues = GetTableValues("event", 37, new string[] { "code", "name", "sports", "gender", "players" }); List <object> athleteValues = GetTableValues("athlete", 989, new string[] { "code", "name", "gender", "nation_code", "event" }); Debug.Assert(athletes.Current.code == (int)athleteValues[0]); Debug.Assert(athletes.Current.name == (string)athleteValues[1]); Debug.Assert(athletes.Current.gender == (string)athleteValues[2]); Debug.Assert(athletes.Current.nation_code == (string)athleteValues[3]); Debug.Assert(athletes.Current.athlete_event == (string)athleteValues[4]); Debug.Assert(athletes.Current.Events.Count == 1); Debug.Assert(athletes.Current.Events[0].code == (int)eventValues[0]); Debug.Assert(athletes.Current.Events[0].name == (string)eventValues[1]); Debug.Assert(athletes.Current.Events[0].sports == (string)eventValues[2]); Debug.Assert(athletes.Current.Events[0].gender == (string)eventValues[3]); Debug.Assert(athletes.Current.Events[0].players == (int)eventValues[4]); Debug.Assert(athletes.Current.Events[0].Athletes.Count == 2); Debug.Assert(athletes.Current.Events[0].Athletes[0].code == (int)athleteValues[0]); Debug.Assert(athletes.Current.Events[0].Athletes[0].name == (string)athleteValues[1]); Debug.Assert(athletes.Current.Events[0].Athletes[0].gender == (string)athleteValues[2]); Debug.Assert(athletes.Current.Events[0].Athletes[0].nation_code == (string)athleteValues[3]); Debug.Assert(athletes.Current.Events[0].Athletes[0].athlete_event == (string)athleteValues[4]); break; } } } //Clean database schema TestCases.ExecuteSQL("drop table AthleteEvent", con); } }
public static void Test_ManyToManyDelete() { Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly); using (CUBRIDConnection con = TestCases.GetDemodbConnection()) { TestCases.ExecuteSQL("drop table if exists AthleteEvent", con); TestCases.ExecuteSQL( "create table AthleteEvent (event_code int, athlete_code int, primary key(event_code,athlete_code))", con); TestCases.ExecuteSQL("insert into Event(code) values(20422)", con); AthleteManyToMany athleteManyToMany = new AthleteManyToMany() { name = "Lucian Bute", gender = "M", nation_code = "ROM", athlete_event = "Boxing", Events = new List <Event>() }; athleteManyToMany.Events.Add(new Event() { code = 20422, sports = "Boxing", name = "70 Kg", gender = "M", players = 2 }); ISessionFactory sessionFactory = cfg.BuildSessionFactory(); using (ISession session = sessionFactory.OpenSession()) { IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator(); int count = 0; while (athletes.MoveNext()) { count++; } Debug.Assert(count == 6677); } using (ISession session = sessionFactory.OpenSession()) { using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) { session.Save(athleteManyToMany); tx.Commit(); } } using (ISession session = sessionFactory.OpenSession()) { IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator(); int count = 0; while (athletes.MoveNext()) { count++; } Debug.Assert(count == 6678); } using (ISession session = sessionFactory.OpenSession()) { using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) { session.Delete(athleteManyToMany); tx.Commit(); } } using (ISession session = sessionFactory.OpenSession()) { IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator(); int count = 0; while (athletes.MoveNext()) { count++; } Debug.Assert(count == 6677); } TestCases.ExecuteSQL("drop table AthleteEvent", con); } }
public static void Test_ManyToManyUpdate() { Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly); using (CUBRIDConnection con = TestCases.GetDemodbConnection()) { TestCases.ExecuteSQL("drop table if exists AthleteEvent", con); TestCases.ExecuteSQL("create table AthleteEvent (event_code int, athlete_code int, primary key(event_code,athlete_code))", con); TestCases.ExecuteSQL("insert into Event(code) values(20422)", con); AthleteManyToMany athleteManyToMany = new AthleteManyToMany { name = "Lucian Bute", gender = "M", nation_code = "ROM", athlete_event = "Boxing", Events = new List <Event>() }; athleteManyToMany.Events.Add(new Event { code = 20422, sports = "Boxing", name = "70 Kg", gender = "M", players = 2 }); ISessionFactory sessionFactory = cfg.BuildSessionFactory(); using (ISession session = sessionFactory.OpenSession()) { using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) { session.Save(athleteManyToMany); tx.Commit(); } } athleteManyToMany.name = "Leonard Doroftei"; athleteManyToMany.Events[0].name = "65 Kg"; using (ISession session = sessionFactory.OpenSession()) { using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) { session.Update(athleteManyToMany); tx.Commit(); } } using (ISession session = sessionFactory.OpenSession()) { IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator(); while (athletes.MoveNext()) { if (athletes.Current.name == "Leonard Doroftei") { List <object> eventValues = GetTableValues("event", 423, new string[] { "code", "name", "sports", "gender", "players" }); List <object> athleteValues = GetTableValues("athlete", 6678, new string[] { "code", "name", "gender", "nation_code", "event" }); Debug.Assert(athletes.Current.code == (int)athleteValues[0]); Debug.Assert(athletes.Current.name == (string)athleteValues[1]); Debug.Assert(athletes.Current.gender == (string)athleteValues[2]); Debug.Assert(athletes.Current.nation_code == (string)athleteValues[3]); Debug.Assert(athletes.Current.athlete_event == (string)athleteValues[4]); Debug.Assert(athletes.Current.Events.Count == 1); Debug.Assert(athletes.Current.Events[0].code == (int)eventValues[0]); Debug.Assert(athletes.Current.Events[0].name == (string)eventValues[1]); Debug.Assert(athletes.Current.Events[0].sports == (string)eventValues[2]); Debug.Assert(athletes.Current.Events[0].gender == (string)eventValues[3]); Debug.Assert(athletes.Current.Events[0].players == (int)eventValues[4]); Debug.Assert(athletes.Current.Events[0].Athletes.Count == 1); Debug.Assert(athletes.Current.Events[0].Athletes[0].name == (string)athleteValues[1]); Debug.Assert(athletes.Current.Events[0].Athletes[0].gender == (string)athleteValues[2]); Debug.Assert(athletes.Current.Events[0].Athletes[0].nation_code == (string)athleteValues[3]); Debug.Assert(athletes.Current.Events[0].Athletes[0].athlete_event == (string)athleteValues[4]); break; } } } using (ISession session = sessionFactory.OpenSession()) { using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) { session.Delete(athleteManyToMany); tx.Commit(); } } TestCases.ExecuteSQL("drop table AthleteEvent", con); } }