■ IStoredProcedure<T> 인터페이스의 Execute 메소드를 사용해 저장 프로시저를 실행하는 방법을 보여준다.
▶ 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 43 44 45 46 47 48 49 50 51 52 53 54 55 |
using System.Collections.Concurrent; using NMemory; using NMemory.StoredProcedures; 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<Member, int> memberTable = database.Tables.Create<Member, int>(member => member.ID, null); memberTable.Insert(new Member() { ID = 1, Name = "김철수" }); memberTable.Insert(new Member() { ID = 2, Name = "홍길동" }); memberTable.Insert(new Member() { ID = 3, Name = "홍삼수" }); memberTable.Insert(new Member() { ID = 4, Name = "김영희" }); memberTable.Insert(new Member() { ID = 5, Name = "이주희" }); IQueryable<Member> queryable = memberTable.Where(member => new Parameter<int>("startID") <= member.ID && member.ID <= new Parameter<int>("endID")); IStoredProcedure<Member> storedProcedure = database.StoredProcedures.Create(queryable); ConcurrentDictionary<string, object> parameterDictionary = new ConcurrentDictionary<string, object>(); parameterDictionary.GetOrAdd("startID", 3); parameterDictionary.GetOrAdd("endID" , 4); List<Member> memberList = storedProcedure.Execute(parameterDictionary).ToList(); foreach(Member member in memberList) { Console.WriteLine($"{member.ID}, {member.Name}"); } } #endregion } |