private void InitDerived() { var objectType = this.ObjectType; var table = this; if (objectType.IsDerived()) { DerivedClassAttribute.CheckUp(objectType); table.DerivedClass = DerivedClassAttribute.GetAttribute(objectType); AddTypTable(table.DerivedClass.TypeKey, table); table.Inheriteds = GetInheriteds(); table.BaseTable = table.Inheriteds.Last(); table.InheritedRoot = table.Inheriteds.First(); var deriveds = table.Inheriteds.ToList(); deriveds.RemoveAt(0); //删除baseRoot deriveds.Add(table); //加上当前表 table.Deriveds = deriveds; } else { table.InheritedRoot = table; //如果不是派生类,那么继承根就是自己 table.Inheriteds = Array.Empty <DataTable>(); table.Deriveds = Array.Empty <DataTable>(); } }
private object ReadMemberFromData(PropertyRepositoryAttribute tip, DynamicData data) { var name = _getNameWithSeparated(tip.PropertyName); using (var temp = SqlHelper.BorrowData()) { var subData = temp.Item; foreach (var p in data) { var dataName = p.Key; if (dataName.StartsWith(name)) { var subName = _getNextName(dataName); subData.Add(subName, p.Value); } } if (subData.IsEmpty()) { if (tip.DomainPropertyType == DomainPropertyType.AggregateRoot) { var idName = _getIdName(tip.PropertyName); var id = data.Get(idName); return(ReadSnapshot(tip, id)); } return(DomainObject.GetEmpty(tip.PropertyType)); } var typeKey = (string)subData.Get(GeneratedField.TypeKeyName); Type objectType = null; if (this.IsDynamic) { objectType = tip.PropertyType; } else { objectType = string.IsNullOrEmpty(typeKey) ? tip.PropertyType : DerivedClassAttribute.GetDerivedType(typeKey); } var child = GetRuntimeTable(this, tip.PropertyName, objectType); //先尝试中构造上下文中得到 return(child.GetObjectFromConstruct(subData) ?? child.CreateObject(objectType, subData, QueryLevel.None)); //成员始终是QueryLevel.None的方式加载 } }
//public static bool IsId(this IDataField field) //{ // return field.Tip.PropertyIsId(); //} /// <summary> /// 类型<paramref name="domainObjectType"/>是否为另外一个领域类型的派生类 /// </summary> /// <param name="domainObjectType"></param> /// <returns></returns> public static bool IsDerived(this Type domainObjectType) { return(DerivedClassAttribute.IsDerived(domainObjectType)); }