public EntityTemplate(EntityDomain entity, IDataTypeFactory dataTypeFactory, EntityTemplate parent) { Name = entity.Name; DataType = CreateDataTypeName(parent?.DataType, entity.Name); Parent = parent; foreach (var attribute in entity.Attributes) { var dataType = dataTypeFactory.MakeValueDataType(attribute.DataType, attribute.AllowNull); if (attribute.IsIdentifier) { IdenfierDataType = dataType; IdenfierGuid = dataType.DataType == EnumDataTypes.Identifier; } else { _attributesTemplate.Add(new AttributeTemplate(attribute, dataType)); } } foreach (var element in entity.Elements) { var dataTypeParameter = CreateDataTypeName(DataType, element.Entity.Name); var dataType = dataTypeFactory.MakeGenericDataType(element.DataType, dataTypeParameter); var entityElement = new EntityTemplate(element.Entity, dataTypeFactory, this); var elementTemplate = new ElementTemplate(entityElement, dataType); _elementsTemplate.Add(elementTemplate); AddReference(elementTemplate); } Attributes = new CollectionTemplate <AttributeTemplate>(_attributesTemplate); Elements = new CollectionTemplate <ElementTemplate>(_elementsTemplate); References = new CollectionTemplate <ElementTemplate>(_referencesTemplate); }
private void AddReference(ElementTemplate reference) { if (Parent == null) { _referencesTemplate.Add(reference); } else { Parent.AddReference(reference); } }