using Dapper; using Dapper.Contrib.Extensions; using NPOI.SS.Formula.Functions; using System.Data.SqlClient; using static DbTableClass; public class newsDetial: news { DbConn dbConn = new DbConn(); SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); public List tags = new List(); public List photos = new List(); public newsDetial() { } public newsDetial(news obj) { Type newsType = obj.GetType(); foreach (var prop in newsType.GetProperties()) { string propName = prop.Name; var valueProperty = newsType.GetProperty(propName); object propValue = valueProperty.GetValue(obj, null); this.GetType().GetProperty(propName).SetValue(this, propValue); } tags = conn.Query("select * from tag where news_uid = @news_uid", new { news_uid = this.news_uid }).ToList(); photos = conn.Query("select * from photo where news_uid = @news_uid", new { news_uid = this.news_uid }).ToList(); } }