Skip to content

Commit

Permalink
Tidy up of the Relational.Design classes.
Browse files Browse the repository at this point in the history
Plus fixes last outstanding point from issue 2714.
  • Loading branch information
lajones committed Sep 21, 2015
1 parent b0615ec commit 057b8df
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAttributeConfiguration> AttributeConfigurations { get; } = new List<IAttributeConfiguration>();
public virtual List<IFluentApiConfiguration> FluentApiConfigurations { get; } = new List<IFluentApiConfiguration>();
public virtual List<PropertyConfiguration> PropertyConfigurations { get; } = new List<PropertyConfiguration>();
Expand All @@ -36,14 +36,6 @@ public virtual List<NavigationPropertyInitializerConfiguration>
public virtual string ErrorMessageAnnotation
=> (string)EntityType[RelationalMetadataModelProvider.AnnotationNameEntityTypeError];

public virtual List<IFluentApiConfiguration> NonAttributeFluentApiConfigurations
{
get
{
return FluentApiConfigurations.Where(fc => !fc.HasAttributeEquivalent).ToList();
}
}

public virtual PropertyConfiguration FindPropertyConfiguration([NotNull] Property property)
{
Check.NotNull(property, nameof(property));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAttributeConfiguration> AttributeConfigurations { get; } = new List<IAttributeConfiguration>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,9 +33,9 @@ public abstract class RelationalMetadataModelProvider : IDatabaseMetadataModelPr
private readonly Dictionary<Property, Property> _relationalToCodeGenPropertyMap =
new Dictionary<Property, Property>();

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; }

Expand All @@ -49,7 +47,7 @@ protected RelationalMetadataModelProvider([NotNull] ILogger logger,

Logger = logger;
CSharpUtilities = cSharpUtilities;
_modelUtilities = modelUtilities;
ModelUtilities = modelUtilities;
}

public virtual IModel GenerateMetadataModel([NotNull] string connectionString)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -211,7 +209,7 @@ private void AddDependentAndPrincipalNavigationPropertyAnnotations([NotNull] IMo
CultureInfo.CurrentCulture,
SelfReferencingPrincipalEndNavigationNamePattern,
dependentEndNavigationPropertyName)
: _modelUtilities.GetPrincipalEndCandidateNavigationPropertyName(foreignKey);
: ModelUtilities.GetPrincipalEndCandidateNavigationPropertyName(foreignKey);
var principalEndNavigationPropertyName =
CSharpUtilities.GenerateCSharpIdentifier(
principalEndNavigationPropertyCandidateName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public virtual string ConvertSqlServerStringLiteral([NotNull] string sqlServerSt
/// <param name="sqlServerStringLiteral"> the string to convert </param>
/// <returns>
/// false if the string can be interpreted as 0, true if it can be
/// intrepreted as 1, otherwise null
/// interpreted as 1, otherwise null
/// </returns>
public virtual bool? ConvertSqlServerBitLiteral([NotNull] string sqlServerStringLiteral)
{
Expand Down Expand Up @@ -118,9 +118,7 @@ public virtual DefaultExpressionOrValue ConvertSqlServerDefaultValue(
};
}

propertyType = propertyType.IsNullableType()
? propertyType.UnwrapNullableType()
: propertyType;
propertyType = propertyType.UnwrapNullableType();

if (typeof(string) == propertyType)
{
Expand Down

0 comments on commit 057b8df

Please sign in to comment.