Ejemplo n.º 1
0
 /// <summary>
 /// Remove navigation properties defined on derived types
 /// </summary>
 /// <param name="model">The model to fix up</param>
 public void Fixup(EntityModelSchema model)
 {
     foreach (var function in model.Functions.ToList().Where(f => f.Annotations.OfType <ServiceOperationAnnotation>().Any(so => so.IsAction)))
     {
         model.Remove(function);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove bags and corresponding features in model for EF provider
        /// </summary>
        /// <param name="model">The model to fix up</param>
        public void Fixup(EntityModelSchema model)
        {
            foreach (var namedStructuralType in model.ComplexTypes.OfType <NamedStructuralType>().Concat(model.EntityTypes.OfType <NamedStructuralType>()))
            {
                foreach (var bag in namedStructuralType.Properties.Where(p => p.PropertyType.HasCollection()))
                {
                    var collectionType = bag.PropertyType as CollectionDataType;
                    bag.PropertyType = collectionType.ElementDataType;
                }
            }

            foreach (var function in model.Functions.ToArray().Where(f => f.ReturnType != null && f.ReturnType.HasCollection()))
            {
                model.Remove(function);
            }

            foreach (var function in model.Functions.ToArray().Where(f => f.Parameters.Any(p => p.DataType.HasCollection())))
            {
                model.Remove(function);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Remove spatial properties and functions
        /// </summary>
        /// <param name="model">The model to fix up</param>
        public void Fixup(EntityModelSchema model)
        {
            foreach (var structuralType in model.EntityTypes.OfType <NamedStructuralType>().Concat(model.ComplexTypes.OfType <NamedStructuralType>()))
            {
                foreach (var spatialProperty in structuralType.Properties.ToArray().Where(p => p.PropertyType.IsSpatial()))
                {
                    structuralType.Properties.Remove(spatialProperty);
                }
            }

            foreach (var function in model.Functions.ToList().Where(f => (f.ReturnType != null && f.ReturnType.IsSpatial()) || f.Parameters.Any(p => p.DataType.IsSpatial())))
            {
                model.Remove(function);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Performs the fixup that ensures every <see cref="EntityType"/>
        /// with an <see cref="ObjectLayerOnlyAnnotation"/> has its members pushed to
        /// derived entity types and the rest of the references to it in the model are fixed up.
        /// </summary>
        /// <param name="model">Model to perform fixup on.</param>
        public void Fixup(EntityModelSchema model)
        {
            var graph = this.BuildGenericTypeResolutionGraph(model);

            foreach (var baseType in model.EntityTypes.Where(e => e.Annotations.OfType <ObjectLayerOnlyAnnotation>().Any() || e.Annotations.OfType <GenericTypeAnnotation>().Any()).ToArray())
            {
                var derivedTypes  = model.EntityTypes.Where(e => e.BaseType == baseType);
                var oldEntitySets = model.EntityContainers.SelectMany(e => e.EntitySets).Where(e => e.EntityType == baseType).ToArray();
                List <AssociationSet> oldAssociationSetsToRemove = new List <AssociationSet>();

                foreach (var derivedType in derivedTypes)
                {
                    // Update entity sets (if any exist).
                    var oldNewMap = new Dictionary <EntitySet, EntitySet>();
                    foreach (var oldEntitySet in oldEntitySets)
                    {
                        // In case of MEST, just using the entity type's name would not yield a unique entity set name,
                        // so we have to append the old EntitySet's name, too.
                        var entitySet = oldNewMap[oldEntitySet] = new EntitySet(derivedType.Name + "_" + oldEntitySet.Name, derivedType);

                        oldEntitySet.Container.Add(entitySet);
                    }

                    this.PushPropertiesToDerivedType(model, graph, baseType, oldAssociationSetsToRemove, derivedType, oldNewMap);

                    derivedType.BaseType = null;
                }

                foreach (var oldEntitySet in oldEntitySets)
                {
                    oldEntitySet.Container.Remove(oldEntitySet);
                }

                foreach (var oldAssociationSet in oldAssociationSetsToRemove)
                {
                    // Sometimes oldAssociationSetsToRemove can contain duplicates if association sets
                    // are copied for multiple derived entity types. If they are already removed
                    // they will be disassociated with the container.
                    if (oldAssociationSet.Container != null)
                    {
                        oldAssociationSet.Container.Remove(oldAssociationSet);
                    }
                }

                // These have already been fixed up, except for association types without navigation properties,
                // which doesn't make any sense in an unmapped base type anyway.
                foreach (var associationType in model.Associations.Where(a => a.Ends.Any(e => e.EntityType == baseType)).ToArray())
                {
                    ValidateAssociationType(baseType, associationType);

                    model.Remove(associationType);
                }

                model.Remove(baseType);
            }

            foreach (var complexType in model.ComplexTypes.Where(c => c.Annotations.OfType <ObjectLayerOnlyAnnotation>().Any()).ToArray())
            {
                model.Remove(complexType);
            }
        }