private void UpdateRelations(IEntity entity) { var entityEx = entity.As <IEntityStatefulExtension>(); if (entityEx == null) { return; } var relProperties = PropertyUnity.GetRelatedProperties(entity.EntityType); foreach (var property in relProperties) { var relationPro = property as RelationProperty; var value = entityEx.GetDirectValue(property); if (value == null) { continue; } switch (relationPro.RelationPropertyType) { case RelationPropertyType.EntitySet: var list = PropertyValueHelper.GetValue <IEnumerable>(value); EntityUtility.AttachPrimaryKeyValues(entity, relationPro, list); Save(list); break; case RelationPropertyType.Entity: SaveRelationEntity(PropertyValueHelper.GetValue <IEntity>(value)); break; } } }
/// <summary> /// 检查有没有关联属性被修改. /// </summary> /// <param name="entity"></param> /// <returns></returns> private bool CheckRelationHasModified(IEntity entity) { //判断实体类型有是不是编译的代理类型,如果不是,取非null的属性,否则使用IsModified判断 var isNotCompiled = entity.GetType().IsNotCompiled(); return(PropertyUnity.GetRelatedProperties(entity.EntityType).Any(s => isNotCompiled ? !PropertyValue.IsEmpty(entity.GetValue(s)) : entity.IsModified(s.Name))); }
/// <summary> /// 检查实体的关联属性。 /// </summary> /// <param name="entity"></param> private void HandleRelationProperties(IEntity entity) { //判断实体类型有是不是编译的代理类型,如果不是,取非null的属性,否则使用IsModified判断 var isNotCompiled = entity.GetType().IsNotCompiled(); var properties = PropertyUnity.GetRelatedProperties(entity.EntityType).Where(m => isNotCompiled ? !PropertyValue.IsEmpty(entity.GetValue(m)) : entity.IsModified(m.Name)); HandleRelationProperties(entity, properties); }
/// <summary> /// 检查实体的关联属性。 /// </summary> /// <param name="entity"></param> private async Task HandleRelationPropertiesAsync(IEntity entity, CancellationToken cancellationToken = default) { //判断实体类型有是不是编译的代理类型,如果不是,取非null的属性,否则使用IsModified判断 var isNotCompiled = entity.GetType().IsNotCompiled(); var properties = PropertyUnity.GetRelatedProperties(entity.EntityType).Where(m => isNotCompiled ? !PropertyValue.IsEmpty(entity.GetValue(m)) : entity.IsModified(m.Name)); await HandleRelationPropertiesAsync(entity, properties, cancellationToken); }
private void InitMapping(string[] fields) { mapping = from s in PropertyUnity.GetProperties(typeof(T)) let index = IndexOf(fields, s) where index != -1 && s is ILoadedProperty select new PropertyMapping { Property = s, Index = index }; alwaysProperties = PropertyUnity.GetRelatedProperties(typeof(T), LoadBehavior.Always); }