Skip to content

Commit

Permalink
Add designTime parameter to IRelationalAnnotationProvider
Browse files Browse the repository at this point in the history
Remove more design-time metadata from runtime model
Fix some configuration loss when reattaching entity types
Add missing SqlServer Metadata methods
Add more tests
  • Loading branch information
AndriySvyryd committed May 18, 2021
1 parent b8eebb2 commit ac1acda
Show file tree
Hide file tree
Showing 85 changed files with 4,513 additions and 1,428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static IServiceCollection AddEntityFrameworkDesignTimeServices(
.TryAddSingleton<IMigrationsCodeGeneratorSelector, MigrationsCodeGeneratorSelector>()
.TryAddSingleton<IModelCodeGenerator, CSharpModelGenerator>()
.TryAddSingleton<IModelCodeGeneratorSelector, ModelCodeGeneratorSelector>()
.TryAddSingleton<ICompiledModelCodeGenerator, CSharpSlimModelCodeGenerator>()
.TryAddSingleton<ICompiledModelCodeGenerator, CSharpRuntimeModelCodeGenerator>()
.TryAddSingleton<ICompiledModelCodeGeneratorSelector, CompiledModelCodeGeneratorSelector>()
.TryAddSingleton<INamedConnectionStringResolver>(
new DesignTimeConnectionStringResolver(applicationServiceProviderAccessor))
Expand Down
20 changes: 15 additions & 5 deletions src/EFCore.Design/Design/Internal/CSharpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ namespace Microsoft.EntityFrameworkCore.Design.Internal
/// </summary>
public class CSharpHelper : ICSharpHelper
{
private readonly IRelationalTypeMappingSource _relationalTypeMappingSource;
private readonly ITypeMappingSource _typeMappingSource;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public CSharpHelper(IRelationalTypeMappingSource relationalTypeMappingSource)
public CSharpHelper(ITypeMappingSource typeMappingSource)
{
_relationalTypeMappingSource = relationalTypeMappingSource;
_typeMappingSource = typeMappingSource;
}

private static readonly IReadOnlyCollection<string> _keywords = new[]
Expand Down Expand Up @@ -267,8 +267,13 @@ private static StringBuilder ChangeFirstLetterCase(StringBuilder builder, bool c
}

var first = builder[index: 0];
if (char.IsUpper(first) == capitalize)
{
return builder;
}

builder.Remove(startIndex: 0, length: 1)
.Insert(index: 0, value: capitalize ? char.ToUpper(first) : char.ToLower(first));
.Insert(index: 0, value: capitalize ? char.ToUpperInvariant(first) : char.ToLowerInvariant(first));

return builder;
}
Expand Down Expand Up @@ -788,12 +793,17 @@ public virtual string UnknownLiteral(object? value)
return Literal(enumValue);
}

if (value is Type type)
{
return Literal(type);
}

if (value is Array array)
{
return Array(literalType.GetElementType()!, array);
}

var mapping = _relationalTypeMappingSource.FindMapping(literalType);
var mapping = _typeMappingSource.FindMapping(literalType);
if (mapping != null)
{
var builder = new StringBuilder();
Expand Down
40 changes: 20 additions & 20 deletions src/EFCore.Design/Properties/DesignStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/EFCore.Design/Properties/DesignStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<value>Could not find type mapping for column '{columnName}' with data type '{dateType}'. Skipping column.</value>
</data>
<data name="CompiledModelConstructorBinding" xml:space="preserve">
<value>The entity type '{entityType}' has a custom constructor binding. This is usually caused by using proxies. Compiled model can't be generated, because custom constructor bindings are not supported.</value>
<value>The entity type '{entityType}' has a custom constructor binding. This is usually caused by using proxies. Compiled model can't be generated, because dynamic proxy types are not supported. If you are not using proxies configure the custom constructor binding in '{customize}' in a partial '{className}' class instead.</value>
</data>
<data name="CompiledModelDefiningQuery" xml:space="preserve">
<value>The entity type '{entityType}' has a defining query configured. Compiled model can't be generated, because defining queries are not supported.</value>
Expand All @@ -142,16 +142,16 @@
<value>The entity type '{entityType}' has a query filter configured. Compiled model can't be generated, because query filters are not supported.</value>
</data>
<data name="CompiledModelTypeMapping" xml:space="preserve">
<value>The property '{entityType}.{property}' has a custom type mapping configured. Compiled model can't be generated, because custom type mappings are not supported.</value>
<value>The property '{entityType}.{property}' has a custom type mapping configured. Configure it in '{customize}' in a partial '{className}' class instead.</value>
</data>
<data name="CompiledModelValueComparer" xml:space="preserve">
<value>The property '{entityType}.{property}' has a value comparer configured. Compiled model can't be generated, because value comparers are not supported.</value>
<value>The property '{entityType}.{property}' has a value comparer configured. Use '{method}' to configure the value comparer type.</value>
</data>
<data name="CompiledModelValueConverter" xml:space="preserve">
<value>The property '{entityType}.{property}' has a value converter configured. Compiled model can't be generated, because value converters are not supported.</value>
<value>The property '{entityType}.{property}' has a value converter configured. Use '{method}' to configure the value converter type.</value>
</data>
<data name="CompiledModelValueGenerator" xml:space="preserve">
<value>The property '{entityType}.{property}' has a value generator configured. Compiled model can't be generated, because value generators are not supported.</value>
<value>The property '{entityType}.{property}' has a value generator configured. Use '{method}' to configure the value generator factory type.</value>
</data>
<data name="ConflictingContextAndMigrationName" xml:space="preserve">
<value>The name you have chosen for the migration, '{name}', is the same as the context class name. Please choose a different name for your migration. Might we suggest 'InitialCreate' for your first migration?</value>
Expand Down
Loading

0 comments on commit ac1acda

Please sign in to comment.