using System.Data.SqlClient; using Dapper.Contrib.Extensions; using Dapper; using static DbTableClass; public class resultClass { public class deptListResult { public string ret = "no"; public string err_code = "0000"; public string message = ""; public List depts = new List(); } public class groupListResult { public string ret = "no"; public string err_code = "0000"; public string message = ""; public List groups = new List(); } public class groupDetail : group { public List users = new List(); } public class userWithDept : user { SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); public List Depts = new List(); public userWithDept() { } public userWithDept(user objData) { Type projectType = objData.GetType(); foreach (var prop in projectType.GetProperties()) { string propName = prop.Name; var valueProperty = projectType.GetProperty(propName); object propValue = valueProperty.GetValue(objData, null); this.GetType().GetProperty(propName).SetValue(this, propValue); } Depts = conn.Query("select * from userDept where user_uid = @user_uid", new { user_uid = this.user_uid }).ToList(); } } }