Ejemplo n.º 1
0
 void _InsertChildren(TableEntityBase info)
 {
     PropertyInfo[] ForeignKeys = info.GetForeignKey();
     if (!ForeignKeys.IsEmpty())    //有子表,处理子表
     {
         ForeignKeys.ForEach(key => //主表里记录子表的列表
         {
             if (key.IsArray() && key.GetChildren().BaseOn <TableEntityBase>())
             {
                 key.ForEach(info, (TableEntityBase item) =>
                 {
                     List <ForeignKeyAttribute> attrs = key.GetAttributes <ForeignKeyAttribute>();
                     attrs.ForEach(a =>
                     {
                         item.SetPropertyValue(a.ChildrenKey, info.GetPropertyValue(a.ParentKey));
                     });
                     Insert(item);
                 });
             }
             else
             {
                 throw new Exception($"属性{key.Name}必须是EntityBase的广义数组");
             }
         });
     }
 }
Ejemplo n.º 2
0
 void _DeleteChildren(TableEntityBase info)
 {
     PropertyInfo[] ForeignKeys = info.GetForeignKey();
     if (!ForeignKeys.IsEmpty())    //有子表,处理子表
     {
         ForeignKeys.ForEach(key => //主表里记录子表的列表
         {
             if (key.IsArray() && key.GetChildren().BaseOn <TableEntityBase>())
             {
                 List <ForeignKeyAttribute> attrs = key.GetAttributes <ForeignKeyAttribute>();
                 TableEntityBase edel             = TableEntityBase.Create(key.GetChildren());
                 attrs.ForEach(attr =>
                 {
                     edel.GetType().GetProperty(attr.ChildrenKey).SetValue(edel, info.GetPropertyValue(attr.ParentKey), null);
                 });
                 _DeleteChildren(edel);
                 DeleteList(edel);
             }
             else
             {
                 throw new Exception($"属性{key.Name}必须是EntityBase的广义数组");
             }
         });
     }
 }