From baefe0daeb7c74aea5b977c7b3c6517da3432192 Mon Sep 17 00:00:00 2001 From: lhiven Date: Sat, 23 Nov 2024 16:11:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96datarow=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E7=B1=BB=E6=97=B6=E5=88=A4=E6=96=AD=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=8C=85=E5=90=AB=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rs.Framework/EntityHelper.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Rs.Framework/EntityHelper.cs b/Rs.Framework/EntityHelper.cs index a1e0347..cd3eda8 100644 --- a/Rs.Framework/EntityHelper.cs +++ b/Rs.Framework/EntityHelper.cs @@ -23,13 +23,16 @@ namespace Rs.Framework PropertyInfo[] pis = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); foreach (PropertyInfo propertyInfo in pis) { - if(propertyInfo.PropertyType.IsEnum) + if(dr.Table.Columns.Contains(propertyInfo.Name)) { - propertyInfo.SetValue(entity, Enum.Parse(propertyInfo.PropertyType, dr[propertyInfo.Name].ToString())); - } - else - { - propertyInfo.SetValue(entity, Convert.ChangeType(dr[propertyInfo.Name], propertyInfo.PropertyType)); + if (propertyInfo.PropertyType.IsEnum) + { + propertyInfo.SetValue(entity, Enum.Parse(propertyInfo.PropertyType, dr[propertyInfo.Name].ToString())); + } + else + { + propertyInfo.SetValue(entity, Convert.ChangeType(dr[propertyInfo.Name], propertyInfo.PropertyType)); + } } } return entity;