internal ResourceChildItem(IResourceModel resourceModel, Entity entity, FilterContext childContext, ResourceClassBase parentResource) : base(resourceModel, entity, childContext) { Parent = parentResource; }
internal EmbeddedObject(ResourceClassBase resourceClass, AssociationView association, FilterContext childFilterContext) : base(resourceClass, association.Name) { Association = association; ObjectType = new ResourceChildItem(resourceClass.ResourceModel, association.OtherEntity, childFilterContext, resourceClass); _parentFullName = Association.ThisEntity.FullName; }
protected internal ResourceClassBase(IResourceModel resourceModel, Entity entity, FilterContext filterContext) : this( resourceModel, entity, filterContext, // Include all collections and embedded objects (but don't include extensions [from another schema] here) () => GetCollectionAssociations(entity), () => GetEmbeddedObjectAssociations(entity)) { }
// Added support for lazily initializing the extension members, similar to EmbeddedObjects private Lazy <IReadOnlyList <Extension> > LazyInitializeExtensions(Entity entity) { var schemaNameMapProvider = entity.DomainModel.SchemaNameMapProvider; return(new Lazy <IReadOnlyList <Extension> >( () => { if (!entity.IsEdFiStandardEntity) { return new List <Extension>(); } // Get collections where the Navigable child is from a different schema var extensionCollections = entity.NavigableChildren.Concat(entity.InheritedNavigableChildren) .Where(c => !c.OtherEntity.Schema.Equals(entity.Schema)) .Where( c => FilterContext.MemberFilter.ShouldIncludeExtension( GetExtensionClassSchemaProperCaseName(c))) .ToList(); // Get collections where the Navigable one-to-one is from a different schema var extensionOneToOnes = entity.NavigableOneToOnes.Concat(entity.InheritedNavigableOneToOnes) .Where(c => !c.OtherEntity.Schema.Equals(entity.Schema)) .Where( c => FilterContext.MemberFilter.ShouldIncludeExtension( GetExtensionClassSchemaProperCaseName(c))) .ToList(); // Build the Resource's Extensions var extensions = entity.Extensions .Select( x => new { Entity = x, Association = x.EdFiStandardEntityAssociation.Inverse, SchemaProperCaseName = x.EdFiStandardEntityAssociation.Inverse.Name, SchemaPhysicalName = schemaNameMapProvider .GetSchemaMapByProperCaseName(x.EdFiStandardEntityAssociation.Inverse.Name) .PhysicalName }) .Where(ext => FilterContext.MemberFilter.ShouldIncludeExtension(ext.SchemaProperCaseName)) .Select( ext => new Extension( this, ext.Association, FilterContext.GetExtensionContext(ext.SchemaProperCaseName), collectionAssociations: () => extensionCollections.Where(a => a.OtherEntity.Schema == ext.SchemaPhysicalName), embeddedObjectAssociations: () => extensionOneToOnes.Where(a => a.OtherEntity.Schema == ext.SchemaPhysicalName) )) .ToList(); // Identify need to implicitly create extension classes (if no extension properties are defined, but collections and embedded objects exist) var implicitExtensionsFromCollections = extensionCollections .Select(GetExtensionClassSchemaProperCaseName) .Distinct() // Where the new schema isn't already in the explicit extensions class .Where( properCaseName => !extensions.Any( x => x.PropertyName.EqualsIgnoreCase(properCaseName))) .Select( properCaseName => new { SchemaProperCaseName = properCaseName, SchemaPhysicalName = schemaNameMapProvider .GetSchemaMapByProperCaseName(properCaseName) .PhysicalName }) // Create an implicit extension class .Select( x => new Extension( this, new ResourceChildItem( ResourceModel, new FullName(x.SchemaPhysicalName, $"{entity.Name}Extension"), this, () => extensionCollections.Where( a => a.OtherEntity.Schema == x.SchemaPhysicalName), () => extensionOneToOnes.Where( a => a.OtherEntity.Schema == x.SchemaPhysicalName), FilterContext.GetExtensionContext(x.SchemaProperCaseName)), x.SchemaProperCaseName)); extensions.AddRange(implicitExtensionsFromCollections); var implicitExtensionsFromEmbeddedObjects = extensionOneToOnes // Where the new schema isn't already in the explicit extensions class .Select(GetExtensionClassSchemaProperCaseName) .Distinct() .Where( properCaseName => !extensions.Any( x => x.PropertyName.EqualsIgnoreCase(properCaseName))) .Select( properCaseName => new { SchemaProperCaseName = properCaseName, SchemaPhysicalName = schemaNameMapProvider .GetSchemaMapByProperCaseName(properCaseName) .PhysicalName }) .Select( x => new Extension( this, new ResourceChildItem( ResourceModel, new FullName(x.SchemaPhysicalName, $"{entity.Name}Extension"), this, () => extensionCollections.Where( a => a.OtherEntity.Schema == x.SchemaPhysicalName), () => extensionOneToOnes.Where( a => a.OtherEntity.Schema == x.SchemaPhysicalName), FilterContext.GetExtensionContext(x.SchemaProperCaseName)), x.SchemaProperCaseName)); extensions.AddRange(implicitExtensionsFromEmbeddedObjects); return extensions; })); }
internal Collection(ResourceClassBase resourceClass, AssociationView association, FilterContext filterContext) : base(resourceClass, association.Name) { Association = association; FilterContext = filterContext ?? FilterContext.NullFilterContext; ItemType = new ResourceChildItem(resourceClass.ResourceModel, association.OtherEntity, FilterContext, resourceClass); if (FilterContext.Definition != null) { // Make sure the XML element matches what we are expecting if (FilterContext.Definition.Name != "Collection") { throw new ArgumentException( string.Format( "The filter context definition XML element reference was a '{0}' element rather than the expected 'Collection' element.", FilterContext.Definition.Name)); } var filterElt = FilterContext.Definition.Element("Filter"); if (filterElt != null) { ValueFilters = new[] { new CollectionItemValueFilter(filterElt) }; } else { ValueFilters = new CollectionItemValueFilter[0]; } } }
internal Resource(IResourceModel resourceModel, Entity entity, FilterContext filterContext) : base(resourceModel, entity, filterContext) { _linkedCollections = LazyInitializeLinkedCollections(entity); _linkedCollectionByName = LazyInitializeLinkedCollectionByName(); }