Пример #1
0
        public IAttributes GetAttributes(bool includeSupertype)
        {
            AttributesCollection collection = new AttributesCollection(Model);

            if (includeSupertype)
            {
                foreach (Attribute a in PrimaryId.Attributes)
                {
                    collection.Add(a);
                }
                IterateToSupertypes(this, delegate(Entity entity) {
                    foreach (Attribute a in entity.Attributes)
                    {
                        if (collection.GetByName(a.Name) == null)                         // Omit primary id in subtypes
                        {
                            collection.Add(a);
                        }
                    }
                });
            }
            else
            {
                foreach (Attribute a in this.Attributes)
                {
                    collection.Add(a);
                }
            }
            return(collection);
        }
Пример #2
0
        public void Check()
        {
            foreach (Attribute a in Attributes)
            {
                a.Check();
            }

            Constraints.Check();

            if (relations.Count == 0)
            {
                Logger.Warning(WarningLevel.Medium, "Entity \"{0}\" has no relations", this.FullName);
            }

            Dictionary <string, Attribute> allAttributes = new Dictionary <string, Attribute>();

            CheckAttributesUniqueness(this, allAttributes);

            CheckRelationNames();

            // Duplicate names in supertypes check
            AttributesCollection collection = new AttributesCollection(Model);

            IterateToSupertypes(this, delegate(Entity entity) {
                foreach (Attribute a in entity.Attributes)
                {
                    Attribute duplicate = collection.GetByName(a.Name);
                    if (duplicate == null)
                    {
                        collection.Add(a);
                    }
                    else
                    {
                        if (!a.IsPrimaryId)
                        {
                            throw new GlException("Attribute name '{0}' is already used in supertype '{1}'. Entity: {2}",
                                                  a.Name, duplicate.Entity.FullName, entity.FullName);
                        }
                    }
                }
            });

            // Note that it is not possible to use identity with union-subclasses mapping strategy
            if (this.HasSupertype && Lamp.Config.Layers.DomainConfig.MappingStrategy == Layers.MappingStrategy.TablePerClass)
            {
                IterateToSupertypes(this.Supertype, delegate(Entity entity) {
                    if (entity.PrimaryId.HasGenerator)
                    {
                        throw new GlException(
                            "Entity '{0}': primary id autoincrement/generator is not allowed with union-subclasses mapping strategy." +
                            "Use TablePerSubclass strategy or 'uuid' type column",
                            entity.FullName);
                    }
                });
            }
        }