using Dapper; using Dapper.Contrib.Extensions; using NPOI.SS.Formula.Functions; using System.Data.SqlClient; using static DbTableClass; public class kolWithTag : kol { DbConn dbConn = new DbConn(); SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); public List tags = new List(); private kol _kol; public kolWithTag() { _kol = new kol(); } public kolWithTag(kol kolObj) { Type kolType = kolObj.GetType(); foreach (var prop in kolType.GetProperties()) { string propName = prop.Name; var valueProperty = kolType.GetProperty(propName); object propValue = valueProperty.GetValue(kolObj, null); this.GetType().GetProperty(propName).SetValue(this, propValue); } _kol = kolObj; loadList(); } public kolWithTag(string kol_uid) { _kol = conn.QueryFirstOrDefault("select * from kol where kol_uid = @kol_uid", new { kol_uid = kol_uid }); if (_kol != null) { Type dataType = _kol.GetType(); foreach (var prop in dataType.GetProperties()) { string propName = prop.Name; var valueProperty = dataType.GetProperty(propName); object propValue = valueProperty.GetValue(_kol, null); this.GetType().GetProperty(propName).SetValue(this, propValue); } loadList(); } } private void loadList() { if (this.kol_uid != "") { tags.Clear(); List kolTags = conn.Query("select A.* from kolTag A, tags B where A.tag_uid = B.tag_uid and A.kol_uid = @kol_uid", new { kol_uid = kol_uid }).ToList(); foreach (kolTag objItem in kolTags) { kolTagDetail objDetail = new kolTagDetail(objItem); tags.Add(objDetail); } } } }