■ Database 클래스를 상속하는 방법을 보여준다.
▶ 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 } |
▶ TestDatabase.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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
using NMemory; using NMemory.Indexes; using NMemory.Tables; namespace TestProject; /// <summary> /// 테스트 데이터베이스 /// </summary> public class TestDatabase : Database { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 그룹 테이블 - GroupTable /// <summary> /// 그룹 테이블 /// </summary> public ITable<Group> GroupTable { get; private set; } #endregion #region 회원 테이블 - MemberTable /// <summary> /// 회원 테이블 /// </summary> public ITable<Member> MemberTable { get; private set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - TestDatabase() /// <summary> /// 생성자 /// </summary> public TestDatabase() { Table<Group , int> groupTable = Tables.Create<Group , int>(g => g.ID, new IdentitySpecification<Group >(g => g.ID, 1, 1)); Table<Member, int> memberTable = Tables.Create<Member, int>(m => m.ID, new IdentitySpecification<Member>(m => m.ID, 1, 1)); GroupTable = groupTable; MemberTable = memberTable; RelationOptions options = new RelationOptions(cascadedDeletion : true); IIndex<Member, int?> memberGroupIDIndex = memberTable.CreateIndex(new RedBlackTreeIndexFactory(), m => m.GroupID); Tables.CreateRelation ( groupTable.PrimaryKeyIndex, memberGroupIDIndex, x => x ?? -1, x => x, options ); } #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 43 44 45 |
namespace TestProject; /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { TestDatabase database = new TestDatabase(); database.GroupTable.Insert(new Group() { Name = "그룹 1"}); database.GroupTable.Insert(new Group() { Name = "그룹 2"}); database.MemberTable.Insert(new Member() { Name = "김철수", GroupID = 1 }); database.MemberTable.Insert(new Member() { Name = "홍길동", GroupID = 1 }); database.MemberTable.Insert(new Member() { Name = "홍삼수", GroupID = 1 }); database.MemberTable.Insert(new Member() { Name = "김영희", GroupID = 2 }); database.MemberTable.Insert(new Member() { Name = "이주희", GroupID = 2 }); foreach(Group group in database.GroupTable) { Console.WriteLine($"{group.ID}, {group.Name}"); } foreach(Member member in database.MemberTable) { Console.WriteLine($"{member.ID}, {member.Name}, {member.GroupID}"); } } #endregion } |