From 057b8df9687e764ba6bd3424356c7038b3c9d78c Mon Sep 17 00:00:00 2001 From: lajones Date: Fri, 18 Sep 2015 10:47:03 -0700 Subject: [PATCH] Tidy up of the Relational.Design classes. Plus fixes last outstanding point from issue 2714. --- .../ReverseEngineering/CodeWriter.cs | 2 +- .../Configuration/AttributeConfiguration.cs | 4 ++-- .../Configuration/EntityConfiguration.cs | 12 ++--------- .../NavigationPropertyConfiguration.cs | 4 ++-- ...igationPropertyInitializerConfiguration.cs | 4 ++-- .../RelationshipConfiguration.cs | 8 ++++---- .../RelationalMetadataModelProvider.cs | 20 +++++++++---------- .../Utilities/SqlServerLiteralUtilities.cs | 6 ++---- 8 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/EntityFramework.Relational.Design/ReverseEngineering/CodeWriter.cs b/src/EntityFramework.Relational.Design/ReverseEngineering/CodeWriter.cs index d9105692a16..2da221c0413 100644 --- a/src/EntityFramework.Relational.Design/ReverseEngineering/CodeWriter.cs +++ b/src/EntityFramework.Relational.Design/ReverseEngineering/CodeWriter.cs @@ -23,7 +23,7 @@ public CodeWriter([NotNull] IFileService fileService) FileService = fileService; } - public virtual IFileService FileService { get;[param: NotNull] set; } + public virtual IFileService FileService { get; } public virtual string FileExtension { get;[param: NotNull] set; } = DefaultFileExtension; /// diff --git a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/AttributeConfiguration.cs b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/AttributeConfiguration.cs index 20f2dc48342..bd7858a3d81 100644 --- a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/AttributeConfiguration.cs +++ b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/AttributeConfiguration.cs @@ -20,9 +20,9 @@ public AttributeConfiguration( : StripAttribute(attributeName) + "(" + string.Join(", ", attributeArguments) + ")"; } - public virtual string AttributeBody { get;[param: NotNull] private set; } + public virtual string AttributeBody { get; } - private static string StripAttribute(string attributeName) + protected static string StripAttribute([NotNull] string attributeName) { return attributeName.EndsWith("Attribute", StringComparison.Ordinal) ? attributeName.Substring(0, attributeName.Length - 9) diff --git a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/EntityConfiguration.cs b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/EntityConfiguration.cs index 343356436b2..e205d66b396 100644 --- a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/EntityConfiguration.cs +++ b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/EntityConfiguration.cs @@ -22,8 +22,8 @@ public EntityConfiguration( EntityType = entityType; } - public virtual ModelConfiguration ModelConfiguration { get;[param: NotNull] private set; } - public virtual IEntityType EntityType { get; [param: NotNull] private set; } + public virtual ModelConfiguration ModelConfiguration { get; } + public virtual IEntityType EntityType { get; } public virtual List AttributeConfigurations { get; } = new List(); public virtual List FluentApiConfigurations { get; } = new List(); public virtual List PropertyConfigurations { get; } = new List(); @@ -36,14 +36,6 @@ public virtual List public virtual string ErrorMessageAnnotation => (string)EntityType[RelationalMetadataModelProvider.AnnotationNameEntityTypeError]; - public virtual List NonAttributeFluentApiConfigurations - { - get - { - return FluentApiConfigurations.Where(fc => !fc.HasAttributeEquivalent).ToList(); - } - } - public virtual PropertyConfiguration FindPropertyConfiguration([NotNull] Property property) { Check.NotNull(property, nameof(property)); diff --git a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/NavigationPropertyConfiguration.cs b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/NavigationPropertyConfiguration.cs index b2d88e0b03b..5aaa3e85be2 100644 --- a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/NavigationPropertyConfiguration.cs +++ b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/NavigationPropertyConfiguration.cs @@ -26,8 +26,8 @@ public NavigationPropertyConfiguration([NotNull] string type, [NotNull] string n } public virtual string ErrorAnnotation { get; [param: NotNull] private set; } - public virtual string Type { get; [param: NotNull] private set; } - public virtual string Name { get; [param: NotNull] private set; } + public virtual string Type { get; } + public virtual string Name { get; } public virtual List AttributeConfigurations { get; } = new List(); } } diff --git a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/NavigationPropertyInitializerConfiguration.cs b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/NavigationPropertyInitializerConfiguration.cs index 09fd75b5dbb..5f0f8e75883 100644 --- a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/NavigationPropertyInitializerConfiguration.cs +++ b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/NavigationPropertyInitializerConfiguration.cs @@ -17,7 +17,7 @@ public NavigationPropertyInitializerConfiguration([NotNull] string navPropName, PrincipalEntityTypeName = principalEntityTypeName; } - public virtual string NavigationPropertyName { get; [param: NotNull] private set; } - public virtual string PrincipalEntityTypeName { get; [param: NotNull] private set; } + public virtual string NavigationPropertyName { get; } + public virtual string PrincipalEntityTypeName { get; } } } diff --git a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/RelationshipConfiguration.cs b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/RelationshipConfiguration.cs index 7cb5f60038b..5bc6a2463e5 100644 --- a/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/RelationshipConfiguration.cs +++ b/src/EntityFramework.Relational.Design/ReverseEngineering/Configuration/RelationshipConfiguration.cs @@ -24,9 +24,9 @@ public RelationshipConfiguration([NotNull] EntityConfiguration entityConfigurati PrincipalEndNavigationPropertyName = principalEndNavigationPropertyName; } - public virtual EntityConfiguration EntityConfiguration { get; [param: NotNull] private set; } - public virtual IForeignKey ForeignKey { get; [param: NotNull] private set; } - public virtual string DependentEndNavigationPropertyName { get; [param: NotNull] private set; } - public virtual string PrincipalEndNavigationPropertyName { get; [param: NotNull] private set; } + public virtual EntityConfiguration EntityConfiguration { get; } + public virtual IForeignKey ForeignKey { get; } + public virtual string DependentEndNavigationPropertyName { get; } + public virtual string PrincipalEndNavigationPropertyName { get; } } } diff --git a/src/EntityFramework.Relational.Design/ReverseEngineering/RelationalMetadataModelProvider.cs b/src/EntityFramework.Relational.Design/ReverseEngineering/RelationalMetadataModelProvider.cs index eabee51768d..d608e088c32 100644 --- a/src/EntityFramework.Relational.Design/ReverseEngineering/RelationalMetadataModelProvider.cs +++ b/src/EntityFramework.Relational.Design/ReverseEngineering/RelationalMetadataModelProvider.cs @@ -3,9 +3,7 @@ using System.Collections.Generic; using System.Globalization; -using System.IO; using System.Linq; -using System.Reflection; using JetBrains.Annotations; using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Relational.Design.Utilities; @@ -35,9 +33,9 @@ public abstract class RelationalMetadataModelProvider : IDatabaseMetadataModelPr private readonly Dictionary _relationalToCodeGenPropertyMap = new Dictionary(); - public virtual ILogger Logger { get; private set; } - public virtual CSharpUtilities CSharpUtilities { get; private set; } - private readonly ModelUtilities _modelUtilities; + public virtual ILogger Logger { get; } + public virtual CSharpUtilities CSharpUtilities { get; } + public virtual ModelUtilities ModelUtilities { get; } protected abstract IRelationalMetadataExtensionProvider ExtensionsProvider { get; } @@ -49,7 +47,7 @@ protected RelationalMetadataModelProvider([NotNull] ILogger logger, Logger = logger; CSharpUtilities = cSharpUtilities; - _modelUtilities = modelUtilities; + ModelUtilities = modelUtilities; } public virtual IModel GenerateMetadataModel([NotNull] string connectionString) @@ -102,8 +100,8 @@ public virtual IModel ConstructCodeGenModel( var codeGenEntityType = codeGenModel .AddEntityType(nameMapper.EntityTypeToClassNameMap[relationalEntityType]); _relationalToCodeGenEntityTypeMap[relationalEntityType] = codeGenEntityType; - codeGenEntityType.Relational().TableName = relationalEntityType.Relational().TableName; - codeGenEntityType.Relational().Schema = relationalEntityType.Relational().Schema; + codeGenEntityType.Relational().TableName = ExtensionsProvider.For(relationalEntityType).TableName; + codeGenEntityType.Relational().Schema = ExtensionsProvider.For(relationalEntityType).Schema; var errorMessage = relationalEntityType[AnnotationNameEntityTypeError]; if (errorMessage != null) { @@ -181,7 +179,7 @@ private void AddDependentAndPrincipalNavigationPropertyAnnotations([NotNull] IMo entityTypeToExistingIdentifiers.Add(entityType, existingIdentifiers); existingIdentifiers.Add(entityType.Name); existingIdentifiers.AddRange( - _modelUtilities.OrderedProperties(entityType).Select(p => p.Name)); + ModelUtilities.OrderedProperties(entityType).Select(p => p.Name)); } foreach (var entityType in codeGenModel.EntityTypes) @@ -191,7 +189,7 @@ private void AddDependentAndPrincipalNavigationPropertyAnnotations([NotNull] IMo { // set up the name of the navigation property on the dependent end of the foreign key var dependentEndNavigationPropertyCandidateName = - _modelUtilities.GetDependentEndCandidateNavigationPropertyName(foreignKey); + ModelUtilities.GetDependentEndCandidateNavigationPropertyName(foreignKey); var dependentEndNavigationPropertyName = CSharpUtilities.GenerateCSharpIdentifier( dependentEndNavigationPropertyCandidateName, @@ -211,7 +209,7 @@ private void AddDependentAndPrincipalNavigationPropertyAnnotations([NotNull] IMo CultureInfo.CurrentCulture, SelfReferencingPrincipalEndNavigationNamePattern, dependentEndNavigationPropertyName) - : _modelUtilities.GetPrincipalEndCandidateNavigationPropertyName(foreignKey); + : ModelUtilities.GetPrincipalEndCandidateNavigationPropertyName(foreignKey); var principalEndNavigationPropertyName = CSharpUtilities.GenerateCSharpIdentifier( principalEndNavigationPropertyCandidateName, diff --git a/src/EntityFramework.SqlServer.Design/Utilities/SqlServerLiteralUtilities.cs b/src/EntityFramework.SqlServer.Design/Utilities/SqlServerLiteralUtilities.cs index 202752538c8..68d85e2d9de 100644 --- a/src/EntityFramework.SqlServer.Design/Utilities/SqlServerLiteralUtilities.cs +++ b/src/EntityFramework.SqlServer.Design/Utilities/SqlServerLiteralUtilities.cs @@ -65,7 +65,7 @@ public virtual string ConvertSqlServerStringLiteral([NotNull] string sqlServerSt /// the string to convert /// /// false if the string can be interpreted as 0, true if it can be - /// intrepreted as 1, otherwise null + /// interpreted as 1, otherwise null /// public virtual bool? ConvertSqlServerBitLiteral([NotNull] string sqlServerStringLiteral) { @@ -118,9 +118,7 @@ public virtual DefaultExpressionOrValue ConvertSqlServerDefaultValue( }; } - propertyType = propertyType.IsNullableType() - ? propertyType.UnwrapNullableType() - : propertyType; + propertyType = propertyType.UnwrapNullableType(); if (typeof(string) == propertyType) {