public override PropertyValue GetValue(IEntity entity, IProperty property) { var referenceProperty = property.As <ReferenceProperty>(); var instanceName = entity.GetInstanceName(); var environment = entity.GetEnvironment(); var identifier = ContextInstanceManager.TryGet(instanceName); if (identifier == null || CheckWithoutLoading(identifier)) { return(PropertyValue.Empty); } var contextProvider = identifier.Provider.GetService <IContextProvider>(); using var scope = identifier.ServiceProvider.TryCreateScope(); using var service = contextProvider.CreateContextService(new ContextServiceContext(scope?.ServiceProvider ?? identifier.ServiceProvider, identifier)); service.InitializeEnvironment(environment).InitializeInstanceName(instanceName); var repProvider = service.CreateRepositoryProvider(referenceProperty.RelationalType); var expression = BuidRelationExpression(entity, referenceProperty); if (expression != null) { var value = Execute(repProvider.Queryable, expression); return(value == null ? PropertyValue.Empty : PropertyValue.NewValue(value)); } return(PropertyValue.Empty); }
public override PropertyValue GetValue(IEntity entity, IProperty property) { var entityProperty = property.As <EntitySetProperty>(); var instanceName = entity.GetInstanceName(); var environment = entity.GetEnvironment(); var identifier = ContextInstanceManager.TryGet(instanceName); if (identifier == null || CheckWithoutLoading(identifier)) { return(PropertyValue.Empty); } var contextProvider = identifier.Provider.GetService <IContextProvider>(); using var scope = identifier.ServiceProvider.TryCreateScope(); using var service = contextProvider.CreateContextService(new ContextServiceContext(scope?.ServiceProvider ?? identifier.ServiceProvider, identifier)); service.InitializeEnvironment(environment).InitializeInstanceName(instanceName); var repProvider = service.CreateRepositoryProvider(entityProperty.RelationalType); var expression = BuidRelationExpression(entity, entityProperty); object result = null; if (expression != null) { result = Execute(repProvider.Queryable, expression); var querySetType = typeof(EntitySet <>).MakeGenericType(entityProperty.RelationalType); var list = querySetType.New(new[] { result }); //设置实体集所属的实体Owner list.As <IEntityRelation>(e => e.Owner = new EntityOwner(entity, property)); return(PropertyValue.NewValue(list)); } return(PropertyValue.Empty); }