/// <summary> /// Merges and creates a list of all of the Properties. <ScalarProperty Name="LineNum" ColumnName="LineNum" /> /// </summary> /// <param name="endProperty">The EndProperty.</param> /// <param name="association">The association.</param> private void MergeScalarProperties(EndProperty endProperty, IAssociation association) { var properties = new List<ScalarProperty>(); foreach (var property in association.Properties) { var associationProperty = !association.Entity.Name.Equals(property.Property.Entity.Name) ? property.Property : property.ForeignProperty; var columnProperty = association.Entity.Name.Equals(property.Property.Entity.Name) ? property.Property : property.ForeignProperty; var prop = endProperty.ScalarProperties.Where(p => p.ColumnName.Equals(columnProperty.KeyName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (prop == null) { // The property doesn't exist so lets create it. prop = new ScalarProperty() { Name = associationProperty.Name }; } else if (!associationProperty.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)) // Column matches that in the database.. If the names are different, it wins. { // The propertyName has been updated. // TODO: Is there a better way to find out if they renamed the Property? //prop.Name = CodeSmith.SchemaHelper.Util.NamingConventions.PropertyName(prop.Name, false); } else { // Update the propertyName so it is always current with SchemaHelper. prop.Name = associationProperty.Name; } prop.ColumnName = columnProperty.KeyName; _mappingEntityPropertyNames[String.Format("{0}-{1}", associationProperty.Entity.Name, associationProperty.KeyName)] = prop.Name; properties.Add(prop); } endProperty.ScalarProperties = properties.Distinct().ToList(); }
private void MergeScalarProperties(FunctionImportComplexTypeMapping mappingFragment, CommandEntity entity) { foreach (var property in mappingFragment.ScalarProperties.Where(p => entity.Properties.Count(prop => prop.KeyName.Equals(p.ColumnName, StringComparison.OrdinalIgnoreCase)) == 0)) _mappingDroppedEntityPropertyNames[String.Format(PROPERTY_KEY, entity.EntityKeyName, property.ColumnName)] = property.Name; var properties = new List<ScalarProperty>(); foreach (var property in entity.Properties) { var prop = mappingFragment.ScalarProperties.Where(p => p.ColumnName.Equals(property.KeyName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (prop == null) { // The property doesn't exist so lets create it. prop = new ScalarProperty() { Name = property.Name }; } else if (!property.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)) // Column matches that in the database.. If the names are different, it wins. { // The propertyName has been updated. // TODO: Is there a better way to find out if they renamed the Property? //prop.Name = prop.Name; } else { // Update the propertyName so it is always current with SchemaHelper. prop.Name = property.Name; } prop.ColumnName = property.KeyName; if (!ExcludeProperty(property as ISchemaProperty) && properties.Count(p => p.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)) == 0) { properties.Add(prop); _mappingEntityPropertyNames[String.Format("{0}-{1}", entity.Name, property.KeyName)] = prop.Name; } } mappingFragment.ScalarProperties = properties.Distinct().ToList(); }