■ TableCollection 클래스의 CreateRelation 메소드를 사용해 테이블 관계를 생성하는 방법을 보여준다.
▶ Group.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
namespace TestProject; /// <summary> /// 그룹 /// </summary> public class Group { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public int ID { get; set; } #endregion #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion } |
▶ Member.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
namespace TestProject; /// <summary> /// 회원 /// </summary> public class Member { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public int ID { get; set; } #endregion #region 성명 - Name /// <summary> /// 성명 /// </summary> public string Name { get; set; } #endregion #region 그룹 ID - GroupID /// <summary> /// 그룹 ID /// </summary> public int? GroupID { get; set; } #endregion } |
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
using NMemory; using NMemory.Indexes; using NMemory.Tables; namespace TestProject; /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { Database database = new Database(); Table<Group , int> groupTable = database.Tables.Create<Group , int>(group => group.ID , null); Table<Member, int> memberTable = database.Tables.Create<Member, int>(member => member.ID, null); IIndex<Member, int?> memberGroupIDIndex = memberTable.CreateIndex(new RedBlackTreeIndexFactory(), member => member.GroupID); database.Tables.CreateRelation ( groupTable.PrimaryKeyIndex, memberGroupIDIndex, x => x ?? -1, x => x ); } #endregion } |