public virtual void AddKeyConfiguration([NotNull] EntityConfiguration entityConfiguration) { Check.NotNull(entityConfiguration, nameof(entityConfiguration)); var entityType = (EntityType)entityConfiguration.EntityType; foreach (var key in entityType.GetKeys()) { if (key == null || key.Properties.Count == 0) { continue; } var conventionKeyProperties = _keyDiscoveryConvention.DiscoverKeyProperties(entityType); if (conventionKeyProperties != null && key.Properties.OrderBy(p => p.Name).SequenceEqual(conventionKeyProperties.OrderBy(p => p.Name))) { continue; } var keyFluentApi = new KeyFluentApiConfiguration("e", key.Properties); if (key.IsPrimaryKey()) { keyFluentApi.IsPrimaryKey = true; if (key.Properties.Count == 1) { keyFluentApi.HasAttributeEquivalent = true; var propertyConfiguration = entityConfiguration.GetOrAddPropertyConfiguration( entityConfiguration, key.Properties.First()); propertyConfiguration.AttributeConfigurations.Add( new AttributeConfiguration(nameof(KeyAttribute))); } } entityConfiguration.FluentApiConfigurations.Add(keyFluentApi); } }
public virtual void AddKeyConfiguration([NotNull] EntityConfiguration entityConfiguration) { Check.NotNull(entityConfiguration, nameof(entityConfiguration)); var entityType = (EntityType)entityConfiguration.EntityType; foreach(var key in entityType.GetKeys()) { if (key == null || key.Properties.Count == 0) { continue; } var conventionKeyProperties = _keyDiscoveryConvention.DiscoverKeyProperties(entityType); if (conventionKeyProperties != null && key.Properties.OrderBy(p => p.Name).SequenceEqual(conventionKeyProperties.OrderBy(p => p.Name))) { continue; } var keyFluentApi = new KeyFluentApiConfiguration("e", key.Properties); if(key.IsPrimaryKey()) { keyFluentApi.IsPrimaryKey = true; if (key.Properties.Count == 1) { keyFluentApi.HasAttributeEquivalent = true; var propertyConfiguration = entityConfiguration.GetOrAddPropertyConfiguration( entityConfiguration, key.Properties.First()); propertyConfiguration.AttributeConfigurations.Add( new AttributeConfiguration(nameof(KeyAttribute))); } } entityConfiguration.FluentApiConfigurations.Add(keyFluentApi); } }