Ejemplo n.º 1
0
 T _SelectChildren <T>(T info) where T : TableEntityBase
 {
     if (info == null)
     {
         return(info);
     }
     PropertyInfo[] ForeignKeys = info.GetForeignKey();
     if (!ForeignKeys.IsEmpty())    //有子表,处理子表
     {
         ForeignKeys.ForEach(key => //主表里记录子表的列表
         {
             if (key.IsArray() && key.GetChildren().BaseOn <TableEntityBase>())
             {
                 Type t = key.GetChildren();
                 TableEntityBase item             = TableEntityBase.Create(t);
                 List <ForeignKeyAttribute> attrs = key.GetAttributes <ForeignKeyAttribute>();
                 attrs.ForEach(a =>
                 {
                     item.SetPropertyValue(a.ChildrenKey, info.GetPropertyValue(a.ParentKey));
                 });
                 List <TableEntityBase> res = SelectList(item, t);
                 key.SetArrValue(info, res);
             }
             else
             {
                 throw new Exception($"属性{key.Name}必须是EntityBase的广义数组");
             }
         });
     }
     return(info);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 读取的内容转换为Entity
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        ///
        private List <TableEntityBase> ReaderToEntity(Type t, DbDataReader reader)
        {
            List <TableEntityBase> res = new List <TableEntityBase>();
            int fieldCount             = reader.FieldCount;

            while (reader.Read())
            {
                TableEntityBase entity = TableEntityBase.Create(t);
                for (int i = 0; i < fieldCount; i++)
                {
                    entity.SetPropertyValue(reader.GetName(i), reader.GetValue(i));
                }
                res.Add(entity);
            }
            reader.Close();
            return(res);
        }