示例#1
0
        private IEnumerable <SuffixesContext> GetContextualClassAndPropertyNameSuffixes(Entity entity)
        {
            yield return(new SuffixesContext());

            // Build the expected name for a hierarchical view (by convention)
            // TODO: Embedded convention - Building hierarchical view name
            var hierarchicalViewFqn = new FullName(entity.Schema, entity.Name + "H");

            // Find the hierarchical view, by convention
            var view = _viewsProvider.LoadViews()
                       .SingleOrDefault(v => new FullName(v.SchemaOwner, v.Name) == hierarchicalViewFqn);

            if (entity.HasSelfReferencingAssociations || view != null)
            {
                // Query the hierarchy recursively
                var context = new SuffixesContext
                {
                    ClassNameSuffix = "H", PropertyNameSuffix = "Hierarchy"
                };

                var columns = view.Columns.Where(c => !c.IsPrimaryKey)

                              // Filter out boilerplate properties
                              .Where(x => !IsAlreadyExplicitlyGeneratedInTemplate(x.Name))

                              // Filter out properties that are part of the entity's identifier
                              .Where(x => entity.Identifier.Properties.All(pkc => !pkc.PropertyName.EqualsIgnoreCase(x.Name)));

                // Convert the IDatabaseSchemaProvider properties to entity properties
                context.ViewProperties = columns
                                         .Select(
                    c =>
                    new EntityProperty(
                        new EntityPropertyDefinition(
                            c.Name.ToMixedCase(),
                            new PropertyType(_databaseTypeTranslator.GetDbType(c.DbDataType), c.Length ?? 0, c.Precision ?? 0, c.Scale ?? 0, c.Nullable))));

                yield return(context);
            }
        }
示例#2
0
        private static IEnumerable <EntityProperty> GetMappedProperties(Entity entity, SuffixesContext contextualSuffix)
        {
            var properties = contextualSuffix.ViewProperties.Any()
                ? contextualSuffix.ViewProperties
                : entity.NonIdentifyingProperties;

            return(properties.Where(p => !p.IsAlreadyDefinedInCSharpEntityBaseClasses()));
        }