public bool DoFillSelf(BaseEntity instance, string Condition, params string[] FieldNames) { if (FieldNames.Length == 0) { FieldNames = null; } SQLQuery sq = new SQLQuery(this.DatabaseName); DataTable dt = sq.GetDTQuery(this.TableName, Condition); List <string> Set = new List <string>(); if (FieldNames != null) { Set.AddRange(FieldNames); } if (dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; foreach (DataColumn Column in dt.Columns) { string Key = Column.ColumnName.ToUpper(); if (dr[Key] == DBNull.Value) { continue; } #region 处理字段 Field Field = null; if (this.PKeyList.ContainsKey(Key)) { Field = this.PKeyList[Key]; } else if (this.FKeyList.ContainsKey(Key)) { Field = this.FKeyList[Key]; } else if (this.FieldList.ContainsKey(Key)) { Field = this.FieldList[Key]; } #endregion #region 赋值 if (FieldNames != null) { if (!Set.Contains(Key)) { continue; } } if (Field != null) { if (Field.SerializedType == ESerializedType.NO) { if (Field.FieldType.IsEnum) { instance[Field.PropertyName] = Convert.ToInt32(dr[Key]); } else if (Field.FieldType.ToString() == "System.Boolean") { instance[Field.PropertyName] = Convert.ToBoolean(dr[Key]); } else if (Field.FieldType.ToString() == "System.DateTime") { instance[Field.PropertyName] = DateTime.Parse(dr[Key].ToString()); } else { instance[Field.PropertyName] = dr[Key]; } } else { instance[Field.PropertyName] = Serialization.Deserialize(dr[Key], Field.FieldType, Field.SerializedType); } } else { instance[Key] = dr[Key]; } #endregion } instance.IsCreated = true; return(true); } return(false); }