Remove SqlServer.Design.Tests

Introduce IAnnotationRenderer interface for provider writers to provide us how to interpret annotations
Flow annotations from DatabaseModel to IModel so that provider can generate provider specific fluent API
Remove special processing inside of SqlServerScaffoldingFactory. All processing should happen while generating database
This commit is contained in:
Smit Patel 2017-06-01 13:29:36 -07:00
Родитель 5f32dc2a23
Коммит 32434d2d86
69 изменённых файлов: 835 добавлений и 2180 удалений

Просмотреть файл

@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Relational", "src\EF
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Sqlite.Core", "src\EFCore.Sqlite.Core\EFCore.Sqlite.Core.csproj", "{A257C01B-BB91-44BA-831C-1E04F7800AC8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.SqlServer.Design", "src\EFCore.SqlServer.Design\EFCore.SqlServer.Design.csproj", "{DA30FC85-8D88-4BB2-98CE-B8A5845BB3EA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Relational.Design", "src\EFCore.Relational.Design\EFCore.Relational.Design.csproj", "{1942C281-C12B-4818-8CC8-C42842871FF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.SqlServer", "src\EFCore.SqlServer\EFCore.SqlServer.csproj", "{99595B81-D47C-40BA-8C61-5328A5A0E4AB}"
@ -39,8 +37,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Sqlite.Tests", "test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.SqlServer.Design.FunctionalTests", "test\EFCore.SqlServer.Design.FunctionalTests\EFCore.SqlServer.Design.FunctionalTests.csproj", "{15033D6B-D415-4932-9462-F2A5AE0B75E8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.SqlServer.Design.Tests", "test\EFCore.SqlServer.Design.Tests\EFCore.SqlServer.Design.Tests.csproj", "{C56644A1-114D-4401-AC79-4B9EC4EDD1E3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.SqlServer.FunctionalTests", "test\EFCore.SqlServer.FunctionalTests\EFCore.SqlServer.FunctionalTests.csproj", "{87AB43B7-767B-467B-9AA9-47BADF850D6A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.SqlServer.Tests", "test\EFCore.SqlServer.Tests\EFCore.SqlServer.Tests.csproj", "{7D1C4E40-0DE6-4C50-AB84-CA8647EA92DF}"
@ -103,10 +99,6 @@ Global
{A257C01B-BB91-44BA-831C-1E04F7800AC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A257C01B-BB91-44BA-831C-1E04F7800AC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A257C01B-BB91-44BA-831C-1E04F7800AC8}.Release|Any CPU.Build.0 = Release|Any CPU
{DA30FC85-8D88-4BB2-98CE-B8A5845BB3EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA30FC85-8D88-4BB2-98CE-B8A5845BB3EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA30FC85-8D88-4BB2-98CE-B8A5845BB3EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA30FC85-8D88-4BB2-98CE-B8A5845BB3EA}.Release|Any CPU.Build.0 = Release|Any CPU
{1942C281-C12B-4818-8CC8-C42842871FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1942C281-C12B-4818-8CC8-C42842871FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1942C281-C12B-4818-8CC8-C42842871FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -151,10 +143,6 @@ Global
{15033D6B-D415-4932-9462-F2A5AE0B75E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15033D6B-D415-4932-9462-F2A5AE0B75E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15033D6B-D415-4932-9462-F2A5AE0B75E8}.Release|Any CPU.Build.0 = Release|Any CPU
{C56644A1-114D-4401-AC79-4B9EC4EDD1E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C56644A1-114D-4401-AC79-4B9EC4EDD1E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C56644A1-114D-4401-AC79-4B9EC4EDD1E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C56644A1-114D-4401-AC79-4B9EC4EDD1E3}.Release|Any CPU.Build.0 = Release|Any CPU
{87AB43B7-767B-467B-9AA9-47BADF850D6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87AB43B7-767B-467B-9AA9-47BADF850D6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87AB43B7-767B-467B-9AA9-47BADF850D6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -244,7 +232,6 @@ Global
{6B102CC4-4396-4A7B-9F72-2C6B5C4D8310} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{6A25DF99-2615-46D8-9532-821764647EE1} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{A257C01B-BB91-44BA-831C-1E04F7800AC8} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{DA30FC85-8D88-4BB2-98CE-B8A5845BB3EA} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{1942C281-C12B-4818-8CC8-C42842871FF5} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{99595B81-D47C-40BA-8C61-5328A5A0E4AB} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{7EAC2B8E-4AF6-40D2-95C0-A6662762A7E0} = {258D5057-81B9-40EC-A872-D21E27452749}
@ -256,7 +243,6 @@ Global
{7BB7D051-56D7-4A40-A29E-3801F5C19239} = {258D5057-81B9-40EC-A872-D21E27452749}
{7E436D99-82A6-496C-A725-0819CBED056D} = {258D5057-81B9-40EC-A872-D21E27452749}
{15033D6B-D415-4932-9462-F2A5AE0B75E8} = {258D5057-81B9-40EC-A872-D21E27452749}
{C56644A1-114D-4401-AC79-4B9EC4EDD1E3} = {258D5057-81B9-40EC-A872-D21E27452749}
{87AB43B7-767B-467B-9AA9-47BADF850D6A} = {258D5057-81B9-40EC-A872-D21E27452749}
{7D1C4E40-0DE6-4C50-AB84-CA8647EA92DF} = {258D5057-81B9-40EC-A872-D21E27452749}
{313F46FE-9962-4A15-805F-FCBDF5A6181E} = {258D5057-81B9-40EC-A872-D21E27452749}

Просмотреть файл

@ -5,11 +5,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
@ -24,6 +27,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
private readonly CSharpUtilities _cSharpUtilities;
private readonly IScaffoldingHelper _scaffoldingHelper;
private readonly IAnnotationRenderer _annotationRenderer;
private IndentedStringBuilder _sb;
private bool _entityTypeBuilderInitialized;
@ -33,12 +37,15 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
/// </summary>
public CSharpDbContextGenerator(
[NotNull] IScaffoldingHelper scaffoldingHelper,
[NotNull] IAnnotationRenderer annotationRenderer,
[NotNull] CSharpUtilities cSharpUtilities)
{
Check.NotNull(scaffoldingHelper, nameof(scaffoldingHelper));
Check.NotNull(annotationRenderer, nameof(annotationRenderer));
Check.NotNull(cSharpUtilities, nameof(cSharpUtilities));
_scaffoldingHelper = scaffoldingHelper;
_annotationRenderer = annotationRenderer;
_cSharpUtilities = cSharpUtilities;
}
@ -147,6 +154,55 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
_sb.AppendLine("protected override void OnModelCreating(ModelBuilder modelBuilder)");
_sb.Append("{");
var annotations = model.GetAnnotations().ToList();
RemoveAnnotation(ref annotations, ScaffoldingAnnotationNames.DatabaseName);
RemoveAnnotation(ref annotations, ScaffoldingAnnotationNames.EntityTypeErrors);
var annotationsToRemove = new List<IAnnotation>();
annotationsToRemove.AddRange(annotations.Where(a => a.Name.StartsWith(RelationalAnnotationNames.SequencePrefix, StringComparison.Ordinal)));
var lines = new List<string>();
foreach (var annotation in annotations)
{
if (_annotationRenderer.IsHandledByConvention(model, annotation))
{
annotationsToRemove.Add(annotation);
}
else
{
var line = _annotationRenderer.GenerateFluentApi(model, annotation);
if (line != null)
{
lines.Add(line);
annotationsToRemove.Add(annotation);
}
}
}
lines.AddRange(GenerateAnnotations(annotations.Except(annotationsToRemove)));
if (lines.Count > 0)
{
using (_sb.Indent())
{
_sb.AppendLine();
_sb.Append("modelBuilder" + lines[0]);
using (_sb.Indent())
{
foreach (var line in lines.Skip(1))
{
_sb.AppendLine();
_sb.Append(line);
}
}
_sb.AppendLine(";");
}
}
using (_sb.Indent())
{
foreach (var entityType in model.GetEntityTypes())
@ -186,11 +242,41 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
GenerateKey(entityType.FindPrimaryKey(), useDataAnnotations);
var annotations = entityType.GetAnnotations().ToList();
RemoveAnnotation(ref annotations, RelationalAnnotationNames.TableName);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.Schema);
RemoveAnnotation(ref annotations, ScaffoldingAnnotationNames.DbSetName);
if (!useDataAnnotations)
{
GenerateTableName(entityType);
}
var annotationsToRemove = new List<IAnnotation>();
var lines = new List<string>();
foreach (var annotation in annotations)
{
if (_annotationRenderer.IsHandledByConvention(entityType, annotation))
{
annotationsToRemove.Add(annotation);
}
else
{
var line = _annotationRenderer.GenerateFluentApi(entityType, annotation);
if (line != null)
{
lines.Add(line);
annotationsToRemove.Add(annotation);
}
}
}
lines.AddRange(GenerateAnnotations(annotations.Except(annotationsToRemove)));
AppendMultiLineFluentApi(entityType, lines);
foreach (var index in entityType.GetIndexes())
{
GenerateIndex(index);
@ -242,7 +328,10 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
return;
}
var annotations = key.GetAnnotations().ToList();
var explicitName = key.Relational().Name != new RelationalKeyAnnotations(key).GetDefaultName();
RemoveAnnotation(ref annotations, RelationalAnnotationNames.Name);
if (key.Properties.Count == 1)
{
@ -271,6 +360,28 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
lines.Add($".{nameof(RelationalKeyBuilderExtensions.HasName)}({_cSharpUtilities.DelimitString(key.Relational().Name)})");
}
var annotationsToRemove = new List<IAnnotation>();
foreach (var annotation in annotations)
{
if (_annotationRenderer.IsHandledByConvention(key, annotation))
{
annotationsToRemove.Add(annotation);
}
else
{
var line = _annotationRenderer.GenerateFluentApi(key, annotation);
if (line != null)
{
lines.Add(line);
annotationsToRemove.Add(annotation);
}
}
}
lines.AddRange(GenerateAnnotations(annotations.Except(annotationsToRemove)));
AppendMultiLineFluentApi(key.DeclaringEntityType, lines);
}
@ -307,9 +418,12 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
$".{nameof(EntityTypeBuilder.HasIndex)}(e => {GenerateLambdaToKey(index.Properties, "e")})"
};
var annotations = index.GetAnnotations().ToList();
if (!string.IsNullOrEmpty(index.Relational().Name))
{
lines.Add($".{nameof(RelationalIndexBuilderExtensions.HasName)}({_cSharpUtilities.DelimitString(index.Relational().Name)})");
RemoveAnnotation(ref annotations, RelationalAnnotationNames.Name);
}
if (index.IsUnique)
@ -320,8 +434,31 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
if (index.Relational().Filter != null)
{
lines.Add($".{nameof(RelationalIndexBuilderExtensions.HasFilter)}({_cSharpUtilities.DelimitString(index.Relational().Filter)})");
RemoveAnnotation(ref annotations, RelationalAnnotationNames.Filter);
}
var annotationsToRemove = new List<IAnnotation>();
foreach (var annotation in annotations)
{
if (_annotationRenderer.IsHandledByConvention(index, annotation))
{
annotationsToRemove.Add(annotation);
}
else
{
var line = _annotationRenderer.GenerateFluentApi(index, annotation);
if (line != null)
{
lines.Add(line);
annotationsToRemove.Add(annotation);
}
}
}
lines.AddRange(GenerateAnnotations(annotations.Except(annotationsToRemove)));
AppendMultiLineFluentApi(index.DeclaringEntityType, lines);
}
@ -332,6 +469,17 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
$".{nameof(EntityTypeBuilder.Property)}(e => e.{property.Name})"
};
var annotations = property.GetAnnotations().ToList();
RemoveAnnotation(ref annotations, RelationalAnnotationNames.ColumnName);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.ColumnType);
RemoveAnnotation(ref annotations, CoreAnnotationNames.MaxLengthAnnotation);
RemoveAnnotation(ref annotations, CoreAnnotationNames.UnicodeAnnotation);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.DefaultValue);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.DefaultValueSql);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.ComputedColumnSql);
RemoveAnnotation(ref annotations, ScaffoldingAnnotationNames.ColumnOrdinal);
if (!useDataAnnotations)
{
if (!property.IsNullable
@ -411,6 +559,28 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
lines.Add($".{methodName}()");
}
var annotationsToRemove = new List<IAnnotation>();
foreach (var annotation in annotations)
{
if (_annotationRenderer.IsHandledByConvention(property, annotation))
{
annotationsToRemove.Add(annotation);
}
else
{
var line = _annotationRenderer.GenerateFluentApi(property, annotation);
if (line != null)
{
lines.Add(line);
annotationsToRemove.Add(annotation);
}
}
}
lines.AddRange(GenerateAnnotations(annotations.Except(annotationsToRemove)));
switch (lines.Count)
{
case 1:
@ -429,6 +599,8 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
private void GenerateRelationship(IForeignKey foreignKey, bool useDataAnnotations)
{
var canUseDataAnnotations = true;
var annotations = foreignKey.GetAnnotations().ToList();
var lines = new List<string>
{
$".{nameof(EntityTypeBuilder.HasOne)}(d => d.{foreignKey.DependentToPrincipal.Name})",
@ -458,6 +630,8 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
lines.Add($".{nameof(ReferenceReferenceBuilder.OnDelete)}({_cSharpUtilities.GenerateLiteral(foreignKey.DeleteBehavior)})");
}
RemoveAnnotation(ref annotations, RelationalAnnotationNames.Name);
if (foreignKey.Relational().Name !=
RelationalForeignKeyAnnotations.GetDefaultForeignKeyName(
foreignKey.DeclaringEntityType.Relational().TableName,
@ -468,6 +642,29 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
lines.Add($".{nameof(RelationalReferenceReferenceBuilderExtensions.HasConstraintName)}({_cSharpUtilities.DelimitString(foreignKey.Relational().Name)})");
}
var annotationsToRemove = new List<IAnnotation>();
foreach (var annotation in annotations)
{
if (_annotationRenderer.IsHandledByConvention(foreignKey, annotation))
{
annotationsToRemove.Add(annotation);
}
else
{
var line = _annotationRenderer.GenerateFluentApi(foreignKey, annotation);
if (line != null)
{
canUseDataAnnotations = false;
lines.Add(line);
annotationsToRemove.Add(annotation);
}
}
}
lines.AddRange(GenerateAnnotations(annotations.Except(annotationsToRemove)));
if (!useDataAnnotations || !canUseDataAnnotations)
{
AppendMultiLineFluentApi(foreignKey.DeclaringEntityType, lines);
@ -557,5 +754,20 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
? $"{lambdaIdentifier}.{properties[0].Name}"
: $"new {{ {string.Join(", ", properties.Select(p => lambdaIdentifier + "." + p.Name))} }}";
}
private void RemoveAnnotation(ref List<IAnnotation> annotations, string annotationName)
{
annotations.Remove(annotations.SingleOrDefault(a => a.Name == annotationName));
}
private IList<string> GenerateAnnotations(IEnumerable<IAnnotation> annotations)
{
return annotations.Select(GenerateAnnotation).ToList();
}
private string GenerateAnnotation(IAnnotation annotation)
{
return $".HasAnnotation({_cSharpUtilities.DelimitString(annotation.Name)}, {_cSharpUtilities.GenerateLiteral((dynamic)annotation.Value)})";
}
}
}

Просмотреть файл

@ -12,6 +12,7 @@ using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Scaffolding.Internal;
@ -148,6 +149,8 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding
VisitTables(modelBuilder, databaseModel.Tables);
VisitForeignKeys(modelBuilder, databaseModel.Tables.SelectMany(table => table.ForeignKeys).ToList());
modelBuilder.Model.AddAnnotations(databaseModel.GetAnnotations());
return modelBuilder;
}
@ -264,6 +267,8 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding
VisitIndexes(builder, table.Indexes);
builder.Metadata.AddAnnotations(table.GetAnnotations());
return builder;
}
@ -350,16 +355,12 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding
}
property.Metadata.Scaffolding().ColumnOrdinal = column.Ordinal;
property.Metadata.AddAnnotations(column.GetAnnotations());
return property;
}
protected virtual RelationalTypeMapping GetTypeMapping([NotNull] ColumnModel column)
{
Check.NotNull(column, nameof(column));
return column.StoreType == null ? null : TypeMapper.FindMapping(column.StoreType);
}
protected virtual KeyBuilder VisitPrimaryKey([NotNull] EntityTypeBuilder builder, [NotNull] TableModel table)
{
Check.NotNull(builder, nameof(builder));
@ -386,7 +387,25 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding
return null;
}
return builder.HasKey(keyColumns.Select(GetPropertyName).ToArray());
var keyBuilder = builder.HasKey(keyColumns.Select(GetPropertyName).ToArray());
var pkColumns = table.Columns.Where(c => c.PrimaryKeyOrdinal.HasValue).ToList();
if (pkColumns.Count == 1
&& pkColumns[0].ValueGenerated == null
&& pkColumns[0].DefaultValue == null)
{
var property = builder.Metadata.FindProperty(GetPropertyName(pkColumns[0]))?.AsProperty();
if (property != null)
{
var conventionalValueGenerated = new RelationalValueGeneratorConvention().GetValueGenerated(property);
if (conventionalValueGenerated == ValueGenerated.OnAdd)
{
property.ValueGenerated = ValueGenerated.Never;
}
}
}
return keyBuilder;
}
protected virtual EntityTypeBuilder VisitIndexes([NotNull] EntityTypeBuilder builder, [NotNull] ICollection<IndexModel> indexes)
@ -458,6 +477,8 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding
indexBuilder.HasName(index.Name);
}
indexBuilder.Metadata.AddAnnotations(index.GetAnnotations());
return indexBuilder;
}
@ -597,6 +618,8 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding
AssignOnDeleteAction(foreignKey, key);
key.AddAnnotations(foreignKey.GetAnnotations());
return key;
}

Просмотреть файл

@ -64,5 +64,10 @@
{
"TypeId": "public static class Microsoft.EntityFrameworkCore.Metadata.ScaffoldingMetadataExtensions",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.EntityFrameworkCore.Scaffolding.RelationalScaffoldingModelFactory : Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory",
"MemberId": "protected virtual Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping GetTypeMapping(Microsoft.EntityFrameworkCore.Scaffolding.Metadata.ColumnModel column)",
"Kind": "Removal"
}
]

Просмотреть файл

@ -0,0 +1,108 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
namespace Microsoft.EntityFrameworkCore.Design.Internal
{
public class AnnotationRendererBase : IAnnotationRenderer
{
public virtual bool IsHandledByConvention(IModel model, IAnnotation annotation)
{
Check.NotNull(model, nameof(model));
Check.NotNull(annotation, nameof(annotation));
return false;
}
public virtual bool IsHandledByConvention(IEntityType entityType, IAnnotation annotation)
{
Check.NotNull(entityType, nameof(entityType));
Check.NotNull(annotation, nameof(annotation));
return false;
}
public virtual bool IsHandledByConvention(IKey key, IAnnotation annotation)
{
Check.NotNull(key, nameof(key));
Check.NotNull(annotation, nameof(annotation));
return false;
}
public virtual bool IsHandledByConvention(IProperty property, IAnnotation annotation)
{
Check.NotNull(property, nameof(property));
Check.NotNull(annotation, nameof(annotation));
return false;
}
public virtual bool IsHandledByConvention(IForeignKey foreignKey, IAnnotation annotation)
{
Check.NotNull(foreignKey, nameof(foreignKey));
Check.NotNull(annotation, nameof(annotation));
return false;
}
public virtual bool IsHandledByConvention(IIndex index, IAnnotation annotation)
{
Check.NotNull(index, nameof(index));
Check.NotNull(annotation, nameof(annotation));
return false;
}
public virtual string GenerateFluentApi(IModel model, IAnnotation annotation)
{
Check.NotNull(model, nameof(model));
Check.NotNull(annotation, nameof(annotation));
return null;
}
public virtual string GenerateFluentApi(IEntityType entityType, IAnnotation annotation)
{
Check.NotNull(entityType, nameof(entityType));
Check.NotNull(annotation, nameof(annotation));
return null;
}
public virtual string GenerateFluentApi(IKey key, IAnnotation annotation)
{
Check.NotNull(key, nameof(key));
Check.NotNull(annotation, nameof(annotation));
return null;
}
public virtual string GenerateFluentApi(IProperty property, IAnnotation annotation)
{
Check.NotNull(property, nameof(property));
Check.NotNull(annotation, nameof(annotation));
return null;
}
public virtual string GenerateFluentApi(IForeignKey foreignKey, IAnnotation annotation)
{
Check.NotNull(foreignKey, nameof(foreignKey));
Check.NotNull(annotation, nameof(annotation));
return null;
}
public virtual string GenerateFluentApi(IIndex index, IAnnotation annotation)
{
Check.NotNull(index, nameof(index));
Check.NotNull(annotation, nameof(annotation));
return null;
}
}
}

Просмотреть файл

@ -0,0 +1,26 @@
// Copyright ([NotNull] c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, [NotNull] Version 2.0. See License.txt in the project root for license information.
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
namespace Microsoft.EntityFrameworkCore.Design
{
public interface IAnnotationRenderer
{
bool IsHandledByConvention([NotNull] IModel model, [NotNull] IAnnotation annotation);
bool IsHandledByConvention([NotNull] IEntityType entityType, [NotNull] IAnnotation annotation);
bool IsHandledByConvention([NotNull] IKey key, [NotNull] IAnnotation annotation);
bool IsHandledByConvention([NotNull] IProperty property, [NotNull] IAnnotation annotation);
bool IsHandledByConvention([NotNull] IForeignKey foreignKey, [NotNull] IAnnotation annotation);
bool IsHandledByConvention([NotNull] IIndex index, [NotNull] IAnnotation annotation);
string GenerateFluentApi([NotNull] IModel model, [NotNull] IAnnotation annotation);
string GenerateFluentApi([NotNull] IEntityType entityType, [NotNull] IAnnotation annotation);
string GenerateFluentApi([NotNull] IKey key, [NotNull] IAnnotation annotation);
string GenerateFluentApi([NotNull] IProperty property, [NotNull] IAnnotation annotation);
string GenerateFluentApi([NotNull] IForeignKey foreignKey, [NotNull] IAnnotation annotation);
string GenerateFluentApi([NotNull] IIndex index, [NotNull] IAnnotation annotation);
}
}

Просмотреть файл

@ -1,67 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
using Microsoft.Extensions.Logging;
namespace Microsoft.EntityFrameworkCore.Diagnostics
{
/// <summary>
/// <para>
/// Event IDs for relational design events that correspond to messages logged to an <see cref="ILogger" />
/// and events sent to a <see cref="DiagnosticSource" />.
/// </para>
/// <para>
/// These IDs are also used with <see cref="WarningsConfigurationBuilder" /> to configure the
/// behavior of warnings.
/// </para>
/// </summary>
public static class SqlServerDesignEventId
{
// Warning: These values must not change between releases.
// Only add new values to the end of sections, never in the middle.
// Try to use <Noun><Verb> naming and be consistent with existing names.
private enum Id
{
// Scaffolding events
ColumnFound = CoreEventId.ProviderDesignBaseId,
ForeignKeyColumnFound,
DefaultSchemaFound,
TypeAliasFound,
DataTypeDoesNotAllowSqlServerIdentityStrategyWarning
}
private static readonly string _scaffoldingPrefix = DbLoggerCategory.Scaffolding.Name + ".";
private static EventId MakeScaffoldingId(Id id) => new EventId((int)id, _scaffoldingPrefix + id);
/// <summary>
/// A column was found.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId ColumnFound = MakeScaffoldingId(Id.ColumnFound);
/// <summary>
/// A column of a foreign key was found.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId ForeignKeyColumnFound = MakeScaffoldingId(Id.ForeignKeyColumnFound);
/// <summary>
/// A default schema was found.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId DefaultSchemaFound = MakeScaffoldingId(Id.DefaultSchemaFound);
/// <summary>
/// A type alias was found.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId TypeAliasFound = MakeScaffoldingId(Id.TypeAliasFound);
/// <summary>
/// The data type does not support the SQL Server identity strategy.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId DataTypeDoesNotAllowSqlServerIdentityStrategyWarning = MakeScaffoldingId(Id.DataTypeDoesNotAllowSqlServerIdentityStrategyWarning);
}
}

Просмотреть файл

@ -1,53 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<Description>Design-time Entity Framework Core Functionality for Microsoft SQL Server.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Microsoft.EntityFrameworkCore.SqlServer.Design</AssemblyName>
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>$(PackageTags);SQL Server</PackageTags>
<CodeAnalysisRuleSet>..\EFCore.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EFCore.Relational.Design\EFCore.Relational.Design.csproj" />
<ProjectReference Include="..\EFCore.SqlServer\EFCore.SqlServer.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Properties\SqlServerDesignStrings.Designer.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>SqlServerDesignStrings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\SqlServerDesignStrings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SqlServerDesignStrings.Designer.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\SqlServerDesignStrings.resx">
<CustomToolNamespace>Microsoft.EntityFrameworkCore.Internal</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="All" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,181 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Storage;
namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public class SqlServerScaffoldingModelFactory : RelationalScaffoldingModelFactory
{
private const int DefaultTimeTimePrecision = 7;
private static readonly ISet<string> _stringAndByteArrayTypesForbiddingMaxLength =
new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "image", "ntext", "text", "rowversion", "timestamp" };
private static readonly ISet<string> _dataTypesAllowingMaxLengthMax =
new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "varchar", "nvarchar", "varbinary" };
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public SqlServerScaffoldingModelFactory(
[NotNull] IDiagnosticsLogger<DbLoggerCategory.Scaffolding> logger,
[NotNull] IRelationalTypeMapper typeMapper,
[NotNull] IDatabaseModelFactory databaseModelFactory,
[NotNull] CandidateNamingService candidateNamingService,
[NotNull] IPluralizer pluralizer,
[NotNull] IScaffoldingHelper scaffoldingHelper)
: base(logger, typeMapper, databaseModelFactory, candidateNamingService, pluralizer, scaffoldingHelper)
{
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
protected override PropertyBuilder VisitColumn(EntityTypeBuilder builder, ColumnModel column)
{
var propertyBuilder = base.VisitColumn(builder, column);
if (propertyBuilder == null)
{
return null;
}
VisitDefaultValue(propertyBuilder, column);
VisitComputedValue(propertyBuilder, column);
return propertyBuilder;
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
protected override RelationalTypeMapping GetTypeMapping(ColumnModel column)
{
RelationalTypeMapping mapping = null;
if (column.StoreType != null)
{
string underlyingDataType = null;
column.Table.Database.SqlServer().TypeAliases?.TryGetValue(
SqlServerDatabaseModelFactory.SchemaQualifiedKey(column.StoreType, column.SqlServer().DataTypeSchemaName), out underlyingDataType);
mapping = TypeMapper.FindMapping(underlyingDataType ?? column.StoreType);
}
return mapping;
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
protected override KeyBuilder VisitPrimaryKey(EntityTypeBuilder builder, TableModel table)
{
var keyBuilder = base.VisitPrimaryKey(builder, table);
if (keyBuilder == null)
{
return null;
}
// If this property is the single integer primary key on the EntityType then
// KeyConvention assumes ValueGeneratedOnAdd(). If the underlying column does
// not have Identity set then we need to set to ValueGeneratedNever() to
// override this behavior.
// TODO use KeyConvention directly to detect when it will be applied
var pkColumns = table.Columns.Where(c => c.PrimaryKeyOrdinal.HasValue).ToList();
if (pkColumns.Count != 1
|| pkColumns[0].ValueGenerated != null
|| pkColumns[0].DefaultValue != null)
{
return keyBuilder;
}
// TODO
var property = builder.Metadata.FindProperty(GetPropertyName(pkColumns[0]));
var propertyType = property?.ClrType?.UnwrapNullableType();
if (propertyType?.IsInteger() == true
|| propertyType == typeof(Guid))
{
property.ValueGenerated = ValueGenerated.Never;
}
return keyBuilder;
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
protected override IndexBuilder VisitIndex(EntityTypeBuilder builder, IndexModel index)
{
var indexBuilder = base.VisitIndex(builder, index);
if (index.SqlServer().IsClustered)
{
indexBuilder?.ForSqlServerIsClustered();
}
return indexBuilder;
}
private void VisitDefaultValue(PropertyBuilder propertyBuilder, ColumnModel column)
{
if (column.DefaultValue != null)
{
propertyBuilder.Metadata.Relational().DefaultValueSql = null;
if (!(column.DefaultValue == "(NULL)"
&& propertyBuilder.Metadata.ClrType.IsNullableType()))
{
propertyBuilder.HasDefaultValueSql(column.DefaultValue);
}
else
{
((Property)propertyBuilder.Metadata).SetValueGenerated(null, ConfigurationSource.Explicit);
}
}
}
private void VisitComputedValue(PropertyBuilder propertyBuilder, ColumnModel column)
{
if (column.ComputedValue != null)
{
propertyBuilder.Metadata.Relational().ComputedColumnSql = null;
if (!(column.ComputedValue == "(NULL)"
&& propertyBuilder.Metadata.ClrType.IsNullableType()))
{
propertyBuilder.HasComputedColumnSql(column.ComputedValue);
}
else
{
((Property)propertyBuilder.Metadata).SetValueGenerated(null, ConfigurationSource.Explicit);
}
}
}
}
}

Просмотреть файл

@ -1,10 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.EntityFrameworkCore.SqlServer.Design.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
// for Moq
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

Просмотреть файл

@ -1,86 +0,0 @@
// <auto-generated />
using System;
using System.Reflection;
using System.Resources;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Logging;
namespace Microsoft.EntityFrameworkCore.Internal
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static class SqlServerDesignStrings
{
private static readonly ResourceManager _resourceManager
= new ResourceManager("Microsoft.EntityFrameworkCore.Properties.SqlServerDesignStrings", typeof(SqlServerDesignStrings).GetTypeInfo().Assembly);
/// <summary>
/// For column {columnId}. This column is set up as an Identity column, but the SQL Server data type is {sqlServerDataType}. This will be mapped to CLR type byte which does not allow the SqlServerValueGenerationStrategy.IdentityColumn setting. Generating a matching Property but ignoring the Identity setting.
/// </summary>
public static readonly EventDefinition<string, string> LogDataTypeDoesNotAllowSqlServerIdentityStrategy
= new EventDefinition<string, string>(
SqlServerDesignEventId.DataTypeDoesNotAllowSqlServerIdentityStrategyWarning,
LogLevel.Warning,
LoggerMessage.Define<string, string>(
LogLevel.Warning,
SqlServerDesignEventId.DataTypeDoesNotAllowSqlServerIdentityStrategyWarning,
_resourceManager.GetString("LogDataTypeDoesNotAllowSqlServerIdentityStrategy")));
/// <summary>
/// Found default schema {defaultSchema}.
/// </summary>
public static readonly EventDefinition<string> LogFoundDefaultSchema
= new EventDefinition<string>(
SqlServerDesignEventId.DefaultSchemaFound,
LogLevel.Debug,
LoggerMessage.Define<string>(
LogLevel.Debug,
SqlServerDesignEventId.DefaultSchemaFound,
_resourceManager.GetString("LogFoundDefaultSchema")));
/// <summary>
/// Found type alias with name: {alias} which maps to underlying data type {dataType}.
/// </summary>
public static readonly EventDefinition<string, string> LogFoundTypeAlias
= new EventDefinition<string, string>(
SqlServerDesignEventId.TypeAliasFound,
LogLevel.Debug,
LoggerMessage.Define<string, string>(
LogLevel.Debug,
SqlServerDesignEventId.TypeAliasFound,
_resourceManager.GetString("LogFoundTypeAlias")));
/// <summary>
/// Found column with table: {tableName}, column name: {columnName}, data type: {dataType}, ordinal: {ordinal}, nullable: {isNullable}, primary key ordinal: {primaryKeyOrdinal}, default value: {defaultValue}, computed value: {computedValue}, precision: {precision}, scale: {scale}, maximum length: {maxLength}, identity: {isIdentity}, computed: {isComputed}.
/// </summary>
public static readonly FallbackEventDefinition LogFoundColumn
= new FallbackEventDefinition(
SqlServerDesignEventId.ColumnFound,
LogLevel.Debug,
_resourceManager.GetString("LogFoundColumn"));
/// <summary>
/// Found foreign key column with table: {tableName}, foreign key name: {fkName}, principal table: {principalTableName}, column name: {columnName}, principal column name: {principalColumnName}, update action: {updateAction}, delete action: {deleteAction}, ordinal: {ordinal}.
/// </summary>
public static readonly FallbackEventDefinition LogFoundForeignKeyColumn
= new FallbackEventDefinition(
SqlServerDesignEventId.ForeignKeyColumnFound,
LogLevel.Debug,
_resourceManager.GetString("LogFoundForeignKeyColumn"));
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);
for (var i = 0; i < formatterNames.Length; i++)
{
value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}");
}
return value;
}
}
}

Просмотреть файл

@ -1,4 +0,0 @@
<#
Session["ResourceFile"] = "SqlServerDesignStrings.resx";
#>
<#@ include file="..\..\..\tools\Resources.tt" #>

Просмотреть файл

@ -1,140 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="LogDataTypeDoesNotAllowSqlServerIdentityStrategy" xml:space="preserve">
<value>For column {columnId}. This column is set up as an Identity column, but the SQL Server data type is {sqlServerDataType}. This will be mapped to CLR type byte which does not allow the SqlServerValueGenerationStrategy.IdentityColumn setting. Generating a matching Property but ignoring the Identity setting.</value>
<comment>Warning SqlServerDesignEventId.DataTypeDoesNotAllowSqlServerIdentityStrategyWarning string string</comment>
</data>
<data name="LogFoundDefaultSchema" xml:space="preserve">
<value>Found default schema {defaultSchema}.</value>
<comment>Debug SqlServerDesignEventId.DefaultSchemaFound string</comment>
</data>
<data name="LogFoundTypeAlias" xml:space="preserve">
<value>Found type alias with name: {alias} which maps to underlying data type {dataType}.</value>
<comment>Debug SqlServerDesignEventId.TypeAliasFound string string</comment>
</data>
<data name="LogFoundColumn" xml:space="preserve">
<value>Found column with table: {tableName}, column name: {columnName}, data type: {dataType}, ordinal: {ordinal}, nullable: {isNullable}, primary key ordinal: {primaryKeyOrdinal}, default value: {defaultValue}, computed value: {computedValue}, precision: {precision}, scale: {scale}, maximum length: {maxLength}, identity: {isIdentity}, computed: {isComputed}.</value>
<comment>Debug SqlServerDesignEventId.ColumnFound string string string int? bool? int? string string int? int? int? bool? bool?</comment>
</data>
<data name="LogFoundForeignKeyColumn" xml:space="preserve">
<value>Found foreign key column with table: {tableName}, foreign key name: {fkName}, principal table: {principalTableName}, column name: {columnName}, principal column name: {principalColumnName}, update action: {updateAction}, delete action: {deleteAction}, ordinal: {ordinal}.</value>
<comment>Debug SqlServerDesignEventId.ForeignKeyColumnFound string string string string string string string int?</comment>
</data>
</root>

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,6 +0,0 @@
[
{
"TypeId": "public enum Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDesignEventId",
"Kind": "Removal"
}
]

Просмотреть файл

@ -0,0 +1,61 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
namespace Microsoft.EntityFrameworkCore.Design.Internal
{
public class SqlServerAnnotationRenderer : AnnotationRendererBase
{
public override bool IsHandledByConvention(IModel model, IAnnotation annotation)
{
Check.NotNull(model, nameof(model));
Check.NotNull(annotation, nameof(annotation));
if (annotation.Name == RelationalAnnotationNames.DefaultSchema
&& string.Equals("dbo", (string)annotation.Value))
{
return true;
}
if (annotation.Name == SqlServerDatabaseModelAnnotationNames.TypeAliases)
{
return true;
}
return false;
}
public override bool IsHandledByConvention(IProperty property, IAnnotation annotation)
{
Check.NotNull(property, nameof(property));
Check.NotNull(annotation, nameof(annotation));
if (annotation.Name == SqlServerDatabaseModelAnnotationNames.DataTypeSchemaName)
{
return true;
}
if (annotation.Name == SqlServerDatabaseModelAnnotationNames.IsIdentity)
{
return true;
}
return false;
}
public override string GenerateFluentApi(IIndex index, IAnnotation annotation)
{
Check.NotNull(index, nameof(index));
Check.NotNull(annotation, nameof(annotation));
return annotation.Name == SqlServerAnnotationNames.Clustered
? $".{nameof(SqlServerIndexBuilderExtensions.ForSqlServerIsClustered)}({((bool)annotation.Value == false ? "false" : "")})"
: null;
}
}
}

Просмотреть файл

@ -1,12 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.EntityFrameworkCore.Scaffolding.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
namespace Microsoft.EntityFrameworkCore.Design.Internal
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
@ -20,9 +21,9 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
/// </summary>
public virtual void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
=> serviceCollection
.AddSingleton<IScaffoldingModelFactory, SqlServerScaffoldingModelFactory>()
.AddSingleton<IRelationalTypeMapper, SqlServerTypeMapper>()
.AddSingleton<IDatabaseModelFactory, SqlServerDatabaseModelFactory>()
.AddSingleton<IScaffoldingHelper, SqlServerScaffoldingHelper>();
.AddSingleton<IScaffoldingHelper, SqlServerScaffoldingHelper>()
.AddSingleton<IAnnotationRenderer, SqlServerAnnotationRenderer>();
}
}

Просмотреть файл

@ -25,7 +25,13 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics
{
// Model validation events
DecimalTypeDefaultWarning = CoreEventId.ProviderBaseId,
ByteIdentityColumnWarning
ByteIdentityColumnWarning,
ColumnFound = CoreEventId.ProviderBaseId + 100,
ForeignKeyColumnFound,
DefaultSchemaFound,
TypeAliasFound,
DataTypeDoesNotAllowSqlServerIdentityStrategyWarning
}
private static readonly string _validationPrefix = DbLoggerCategory.Model.Validation.Name + ".";
@ -56,5 +62,38 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics
/// </para>
/// </summary>
public static readonly EventId ByteIdentityColumnWarning = MakeValidationId(Id.ByteIdentityColumnWarning);
private static readonly string _scaffoldingPrefix = DbLoggerCategory.Scaffolding.Name + ".";
private static EventId MakeScaffoldingId(Id id) => new EventId((int)id, _scaffoldingPrefix + id);
/// <summary>
/// A column was found.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId ColumnFound = MakeScaffoldingId(Id.ColumnFound);
/// <summary>
/// A column of a foreign key was found.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId ForeignKeyColumnFound = MakeScaffoldingId(Id.ForeignKeyColumnFound);
/// <summary>
/// A default schema was found.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId DefaultSchemaFound = MakeScaffoldingId(Id.DefaultSchemaFound);
/// <summary>
/// A type alias was found.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId TypeAliasFound = MakeScaffoldingId(Id.TypeAliasFound);
/// <summary>
/// The data type does not support the SQL Server identity strategy.
/// This event is in the <see cref="DbLoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId DataTypeDoesNotAllowSqlServerIdentityStrategyWarning = MakeScaffoldingId(Id.DataTypeDoesNotAllowSqlServerIdentityStrategyWarning);
}
}

Просмотреть файл

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.Extensions.Logging;
namespace Microsoft.EntityFrameworkCore.Internal
@ -13,8 +14,80 @@ namespace Microsoft.EntityFrameworkCore.Internal
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static class SqlServerDesignLoggerExtensions
public static class SqlServerLoggerExtensions
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void DecimalTypeDefaultWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Model.Validation> diagnostics,
[NotNull] IProperty property)
{
var definition = SqlServerStrings.LogDefaultDecimalTypeColumn;
// Checking for enabled here to avoid string formatting if not needed.
if (diagnostics.GetLogBehavior(definition.EventId, definition.Level) != WarningBehavior.Ignore)
{
definition.Log(diagnostics, property.Name, property.DeclaringEntityType.DisplayName());
}
if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new PropertyEventData(
definition,
DecimalTypeDefaultWarning,
property));
}
}
private static string DecimalTypeDefaultWarning(EventDefinitionBase definition, EventDataBase payload)
{
var d = (EventDefinition<string, string>)definition;
var p = (PropertyEventData)payload;
return d.GenerateMessage(
p.Property.Name,
p.Property.DeclaringEntityType.DisplayName());
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void ByteIdentityColumnWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Model.Validation> diagnostics,
[NotNull] IProperty property)
{
var definition = SqlServerStrings.LogByteIdentityColumn;
// Checking for enabled here to avoid string formatting if not needed.
if (diagnostics.GetLogBehavior(definition.EventId, definition.Level) != WarningBehavior.Ignore)
{
definition.Log(diagnostics, property.Name, property.DeclaringEntityType.DisplayName());
}
if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new PropertyEventData(
definition,
ByteIdentityColumnWarning,
property));
}
}
private static string ByteIdentityColumnWarning(EventDefinitionBase definition, EventDataBase payload)
{
var d = (EventDefinition<string, string>)definition;
var p = (PropertyEventData)payload;
return d.GenerateMessage(
p.Property.Name,
p.Property.DeclaringEntityType.DisplayName());
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
@ -35,7 +108,7 @@ namespace Microsoft.EntityFrameworkCore.Internal
[CanBeNull] bool? identity,
[CanBeNull] bool? computed)
{
var definition = SqlServerDesignStrings.LogFoundColumn;
var definition = SqlServerStrings.LogFoundColumn;
Debug.Assert(LogLevel.Debug == definition.Level);
@ -100,7 +173,7 @@ namespace Microsoft.EntityFrameworkCore.Internal
[CanBeNull] string deleteAction,
int? ordinal)
{
var definition = SqlServerDesignStrings.LogFoundForeignKeyColumn;
var definition = SqlServerStrings.LogFoundForeignKeyColumn;
Debug.Assert(LogLevel.Debug == definition.Level);
@ -148,7 +221,7 @@ namespace Microsoft.EntityFrameworkCore.Internal
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string schemaName)
{
var definition = SqlServerDesignStrings.LogFoundDefaultSchema;
var definition = SqlServerStrings.LogFoundDefaultSchema;
definition.Log(diagnostics, schemaName);
@ -172,7 +245,7 @@ namespace Microsoft.EntityFrameworkCore.Internal
[CanBeNull] string typeAliasName,
[CanBeNull] string systemTypeName)
{
var definition = SqlServerDesignStrings.LogFoundTypeAlias;
var definition = SqlServerStrings.LogFoundTypeAlias;
definition.Log(diagnostics, typeAliasName, systemTypeName);
@ -197,7 +270,7 @@ namespace Microsoft.EntityFrameworkCore.Internal
[CanBeNull] string columnName,
[CanBeNull] string typeName)
{
var definition = SqlServerDesignStrings.LogDataTypeDoesNotAllowSqlServerIdentityStrategy;
var definition = SqlServerStrings.LogDataTypeDoesNotAllowSqlServerIdentityStrategy;
definition.Log(diagnostics, columnName, typeName);

Просмотреть файл

@ -4,6 +4,6 @@
using Microsoft.EntityFrameworkCore.Design;
[assembly: DesignTimeProviderServices(
typeName: "Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqlServerDesignTimeServices",
assemblyName: "Microsoft.EntityFrameworkCore.SqlServer.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
packageName: "Microsoft.EntityFrameworkCore.SqlServer.Design")]
typeName: "Microsoft.EntityFrameworkCore.Design.Internal.SqlServerDesignTimeServices",
assemblyName: "Microsoft.EntityFrameworkCore.SqlServer, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
packageName: "Microsoft.EntityFrameworkCore.SqlServer")]

Просмотреть файл

@ -106,6 +106,60 @@ namespace Microsoft.EntityFrameworkCore.Internal
GetString("IncompatibleTableMemoryOptimizedMismatch", nameof(table), nameof(entityType), nameof(otherEntityType), nameof(memoryOptimizedEntityType), nameof(nonMemoryOptimizedEntityType)),
table, entityType, otherEntityType, memoryOptimizedEntityType, nonMemoryOptimizedEntityType);
/// <summary>
/// For column {columnId}. This column is set up as an Identity column, but the SQL Server data type is {sqlServerDataType}. This will be mapped to CLR type byte which does not allow the SqlServerValueGenerationStrategy.IdentityColumn setting. Generating a matching Property but ignoring the Identity setting.
/// </summary>
public static readonly EventDefinition<string, string> LogDataTypeDoesNotAllowSqlServerIdentityStrategy
= new EventDefinition<string, string>(
SqlServerEventId.DataTypeDoesNotAllowSqlServerIdentityStrategyWarning,
LogLevel.Warning,
LoggerMessage.Define<string, string>(
LogLevel.Warning,
SqlServerEventId.DataTypeDoesNotAllowSqlServerIdentityStrategyWarning,
_resourceManager.GetString("LogDataTypeDoesNotAllowSqlServerIdentityStrategy")));
/// <summary>
/// Found default schema {defaultSchema}.
/// </summary>
public static readonly EventDefinition<string> LogFoundDefaultSchema
= new EventDefinition<string>(
SqlServerEventId.DefaultSchemaFound,
LogLevel.Debug,
LoggerMessage.Define<string>(
LogLevel.Debug,
SqlServerEventId.DefaultSchemaFound,
_resourceManager.GetString("LogFoundDefaultSchema")));
/// <summary>
/// Found type alias with name: {alias} which maps to underlying data type {dataType}.
/// </summary>
public static readonly EventDefinition<string, string> LogFoundTypeAlias
= new EventDefinition<string, string>(
SqlServerEventId.TypeAliasFound,
LogLevel.Debug,
LoggerMessage.Define<string, string>(
LogLevel.Debug,
SqlServerEventId.TypeAliasFound,
_resourceManager.GetString("LogFoundTypeAlias")));
/// <summary>
/// Found column with table: {tableName}, column name: {columnName}, data type: {dataType}, ordinal: {ordinal}, nullable: {isNullable}, primary key ordinal: {primaryKeyOrdinal}, default value: {defaultValue}, computed value: {computedValue}, precision: {precision}, scale: {scale}, maximum length: {maxLength}, identity: {isIdentity}, computed: {isComputed}.
/// </summary>
public static readonly FallbackEventDefinition LogFoundColumn
= new FallbackEventDefinition(
SqlServerEventId.ColumnFound,
LogLevel.Debug,
_resourceManager.GetString("LogFoundColumn"));
/// <summary>
/// Found foreign key column with table: {tableName}, foreign key name: {fkName}, principal table: {principalTableName}, column name: {columnName}, principal column name: {principalColumnName}, update action: {updateAction}, delete action: {deleteAction}, ordinal: {ordinal}.
/// </summary>
public static readonly FallbackEventDefinition LogFoundForeignKeyColumn
= new FallbackEventDefinition(
SqlServerEventId.ForeignKeyColumnFound,
LogLevel.Debug,
_resourceManager.GetString("LogFoundForeignKeyColumn"));
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);

Просмотреть файл

@ -152,4 +152,24 @@
<data name="IncompatibleTableMemoryOptimizedMismatch" xml:space="preserve">
<value>Cannot use table '{table}' for entity type '{entityType}' since it is being used for entity type '{otherEntityType}' and entity type '{memoryOptimizedEntityType}' is marked as memory-optimized, but entity type '{nonMemoryOptimizedEntityType}' is not.</value>
</data>
<data name="LogDataTypeDoesNotAllowSqlServerIdentityStrategy" xml:space="preserve">
<value>For column {columnId}. This column is set up as an Identity column, but the SQL Server data type is {sqlServerDataType}. This will be mapped to CLR type byte which does not allow the SqlServerValueGenerationStrategy.IdentityColumn setting. Generating a matching Property but ignoring the Identity setting.</value>
<comment>Warning SqlServerEventId.DataTypeDoesNotAllowSqlServerIdentityStrategyWarning string string</comment>
</data>
<data name="LogFoundDefaultSchema" xml:space="preserve">
<value>Found default schema {defaultSchema}.</value>
<comment>Debug SqlServerEventId.DefaultSchemaFound string</comment>
</data>
<data name="LogFoundTypeAlias" xml:space="preserve">
<value>Found type alias with name: {alias} which maps to underlying data type {dataType}.</value>
<comment>Debug SqlServerEventId.TypeAliasFound string string</comment>
</data>
<data name="LogFoundColumn" xml:space="preserve">
<value>Found column with table: {tableName}, column name: {columnName}, data type: {dataType}, ordinal: {ordinal}, nullable: {isNullable}, primary key ordinal: {primaryKeyOrdinal}, default value: {defaultValue}, computed value: {computedValue}, precision: {precision}, scale: {scale}, maximum length: {maxLength}, identity: {isIdentity}, computed: {isComputed}.</value>
<comment>Debug SqlServerEventId.ColumnFound string string string int? bool? int? string string int? int? int? bool? bool?</comment>
</data>
<data name="LogFoundForeignKeyColumn" xml:space="preserve">
<value>Found foreign key column with table: {tableName}, foreign key name: {fkName}, principal table: {principalTableName}, column name: {columnName}, principal column name: {principalColumnName}, update action: {updateAction}, delete action: {deleteAction}, ordinal: {ordinal}.</value>
<comment>Debug SqlServerEventId.ForeignKeyColumnFound string string string string string string string int?</comment>
</data>
</root>

Просмотреть файл

@ -159,9 +159,11 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
var command = _connection.CreateCommand();
command.CommandText = "SELECT SCHEMA_NAME()";
var schema = command.ExecuteScalar() as string ?? "dbo";
Logger.DefaultSchemaFound(schema);
_databaseModel.DefaultSchemaName = schema;
if (command.ExecuteScalar() is string schema)
{
Logger.DefaultSchemaFound(schema);
_databaseModel.DefaultSchemaName = schema;
}
}
private void GetTypeAliases()
@ -292,7 +294,12 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
if (!string.IsNullOrEmpty(MemoryOptimizedTableColumn))
{
table[SqlServerAnnotationNames.MemoryOptimized] = reader.GetValueOrDefault<bool?>("is_memory_optimized");
var isTableMemoryOptimized = reader.GetValueOrDefault<bool?>("is_memory_optimized");
if (isTableMemoryOptimized == true)
{
table[SqlServerAnnotationNames.MemoryOptimized] = true;
}
}
Logger.TableFound(table.DisplayName);
@ -422,6 +429,16 @@ WHERE t.name <> '" + HistoryRepository.DefaultTableName + "'" +
}
}
if (defaultValue == "(NULL)")
{
defaultValue = null;
}
if (computedValue == "(NULL)")
{
computedValue = null;
}
var column = new ColumnModel
{
Table = table,
@ -521,7 +538,11 @@ ORDER BY object_schema_name(i.object_id), object_name(i.object_id), i.name, ic.k
IsUnique = isUnique,
Filter = hasFilter ? filterDefinition : null
};
index.SqlServer().IsClustered = typeDesc == "CLUSTERED";
if (typeDesc == "CLUSTERED")
{
index[SqlServerAnnotationNames.Clustered] = true;
}
table.Indexes.Add(index);
}

Просмотреть файл

@ -1,89 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.Internal
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static class SqlServerLoggerExtensions
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void DecimalTypeDefaultWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Model.Validation> diagnostics,
[NotNull] IProperty property)
{
var definition = SqlServerStrings.LogDefaultDecimalTypeColumn;
// Checking for enabled here to avoid string formatting if not needed.
if (diagnostics.GetLogBehavior(definition.EventId, definition.Level) != WarningBehavior.Ignore)
{
definition.Log(diagnostics, property.Name, property.DeclaringEntityType.DisplayName());
}
if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new PropertyEventData(
definition,
DecimalTypeDefaultWarning,
property));
}
}
private static string DecimalTypeDefaultWarning(EventDefinitionBase definition, EventDataBase payload)
{
var d = (EventDefinition<string, string>)definition;
var p = (PropertyEventData)payload;
return d.GenerateMessage(
p.Property.Name,
p.Property.DeclaringEntityType.DisplayName());
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void ByteIdentityColumnWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Model.Validation> diagnostics,
[NotNull] IProperty property)
{
var definition = SqlServerStrings.LogByteIdentityColumn;
// Checking for enabled here to avoid string formatting if not needed.
if (diagnostics.GetLogBehavior(definition.EventId, definition.Level) != WarningBehavior.Ignore)
{
definition.Log(diagnostics, property.Name, property.DeclaringEntityType.DisplayName());
}
if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new PropertyEventData(
definition,
ByteIdentityColumnWarning,
property));
}
}
private static string ByteIdentityColumnWarning(EventDefinitionBase definition, EventDataBase payload)
{
var d = (EventDefinition<string, string>)definition;
var p = (PropertyEventData)payload;
return d.GenerateMessage(
p.Property.Name,
p.Property.DeclaringEntityType.DisplayName());
}
}
}

Просмотреть файл

@ -23,6 +23,7 @@ namespace Microsoft.EntityFrameworkCore.Design.Internal
=> serviceCollection
.AddSingleton<IRelationalTypeMapper, SqliteTypeMapper>()
.AddSingleton<IDatabaseModelFactory, SqliteDatabaseModelFactory>()
.AddSingleton<IScaffoldingHelper, SqliteScaffoldingHelper>();
.AddSingleton<IScaffoldingHelper, SqliteScaffoldingHelper>()
.AddSingleton<IAnnotationRenderer, AnnotationRendererBase>();
}
}

Просмотреть файл

@ -2,7 +2,10 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.ReverseEngineering;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using Microsoft.EntityFrameworkCore.TestUtilities;
@ -26,7 +29,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
new FakeScaffoldingModelFactory(new FakeDiagnosticsLogger<DbLoggerCategory.Scaffolding>()),
new CSharpScaffoldingGenerator(
new InMemoryFileService(),
new CSharpDbContextGenerator(new FakeScaffoldingHelper(), CSharpUtilities.Instance),
new CSharpDbContextGenerator(new FakeScaffoldingHelper(), new FakeAnnotationRenderer(), CSharpUtilities.Instance),
new CSharpEntityTypeGenerator(CSharpUtilities.Instance)),
CSharpUtilities.Instance);
@ -58,5 +61,68 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
throw new NotImplementedException();
}
}
public class FakeAnnotationRenderer : IAnnotationRenderer
{
public string GenerateFluentApi(IModel model, IAnnotation annotation)
{
throw new NotImplementedException();
}
public string GenerateFluentApi(IEntityType entityType, IAnnotation annotation)
{
throw new NotImplementedException();
}
public string GenerateFluentApi(IKey key, IAnnotation annotation)
{
throw new NotImplementedException();
}
public string GenerateFluentApi(IProperty property, IAnnotation annotation)
{
throw new NotImplementedException();
}
public string GenerateFluentApi(IForeignKey foreignKey, IAnnotation annotation)
{
throw new NotImplementedException();
}
public string GenerateFluentApi(IIndex index, IAnnotation annotation)
{
throw new NotImplementedException();
}
public bool IsHandledByConvention(IModel model, IAnnotation annotation)
{
throw new NotImplementedException();
}
public bool IsHandledByConvention(IEntityType entityType, IAnnotation annotation)
{
throw new NotImplementedException();
}
public bool IsHandledByConvention(IKey key, IAnnotation annotation)
{
throw new NotImplementedException();
}
public bool IsHandledByConvention(IProperty property, IAnnotation annotation)
{
throw new NotImplementedException();
}
public bool IsHandledByConvention(IForeignKey foreignKey, IAnnotation annotation)
{
throw new NotImplementedException();
}
public bool IsHandledByConvention(IIndex index, IAnnotation annotation)
{
throw new NotImplementedException();
}
}
}
}

Просмотреть файл

@ -29,7 +29,6 @@
<ItemGroup>
<ProjectReference Include="..\..\src\EFCore.Relational.Design.Specification.Tests\EFCore.Relational.Design.Specification.Tests.csproj" />
<ProjectReference Include="..\..\src\EFCore.SqlServer\EFCore.SqlServer.csproj" />
<ProjectReference Include="..\..\src\EFCore.SqlServer.Design\EFCore.SqlServer.Design.csproj" />
<ProjectReference Include="..\EFCore.SqlServer.FunctionalTests\EFCore.SqlServer.FunctionalTests.csproj" />
</ItemGroup>

Просмотреть файл

@ -371,7 +371,7 @@ CREATE TABLE "OneToOneFKToUniqueKeyDependent" (
"SomeColumn" nvarchar (20) NOT NULL,
"OneToOneFKToUniqueKeyDependentFK1" "int" NULL,
"OneToOneFKToUniqueKeyDependentFK2" "int" NULL,
CONSTRAINT "PK_OneToOneFKToUniqueKeyDependent" PRIMARY KEY CLUSTERED
CONSTRAINT "PK_OneToOneFKToUniqueKeyDependent" PRIMARY KEY
(
"OneToOneFKToUniqueKeyDependentID1", "OneToOneFKToUniqueKeyDependentID2"
),
@ -381,7 +381,7 @@ CREATE TABLE "OneToOneFKToUniqueKeyDependent" (
) REFERENCES "dbo"."OneToOneFKToUniqueKeyPrincipal" (
"OneToOneFKToUniqueKeyPrincipalUniqueKey1", "OneToOneFKToUniqueKeyPrincipalUniqueKey2"
),
CONSTRAINT "UK_OneToOneFKToUniqueKeyDependent" UNIQUE
CONSTRAINT "UK_OneToOneFKToUniqueKeyDependent" UNIQUE CLUSTERED
(
"OneToOneFKToUniqueKeyDependentFK1", "OneToOneFKToUniqueKeyDependentFK2"
)

Просмотреть файл

@ -383,7 +383,8 @@ namespace E2ETest.Namespace
entity.HasIndex(e => new { e.OneToOneFktoUniqueKeyDependentFk1, e.OneToOneFktoUniqueKeyDependentFk2 })
.HasName("UK_OneToOneFKToUniqueKeyDependent")
.IsUnique();
.IsUnique()
.ForSqlServerIsClustered();
entity.Property(e => e.OneToOneFktoUniqueKeyDependentId1).HasColumnName("OneToOneFKToUniqueKeyDependentID1");

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
public partial class AllDataTypes
{

Просмотреть файл

@ -2,7 +2,7 @@ using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
public partial class AttributesContext : DbContext
{
@ -116,7 +116,8 @@ namespace E2ETest.Namespace
entity.HasIndex(e => new { e.OneToOneFktoUniqueKeyDependentFk1, e.OneToOneFktoUniqueKeyDependentFk2 })
.HasName("UK_OneToOneFKToUniqueKeyDependent")
.IsUnique();
.IsUnique()
.ForSqlServerIsClustered();
entity.HasOne(d => d.OneToOneFktoUniqueKeyDependentFk)
.WithOne(p => p.OneToOneFktoUniqueKeyDependent)

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
[Table("MultipleFKsDependent")]
public partial class MultipleFksDependent

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
[Table("MultipleFKsPrincipal")]
public partial class MultipleFksPrincipal

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
public partial class OneToManyDependent
{

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
public partial class OneToManyPrincipal
{

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
public partial class OneToOneDependent
{

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
[Table("OneToOneFKToUniqueKeyDependent")]
public partial class OneToOneFktoUniqueKeyDependent

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
[Table("OneToOneFKToUniqueKeyPrincipal")]
public partial class OneToOneFktoUniqueKeyPrincipal

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
public partial class OneToOnePrincipal
{

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
[Table("OneToOneSeparateFKDependent")]
public partial class OneToOneSeparateFkdependent

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
[Table("OneToOneSeparateFKPrincipal")]
public partial class OneToOneSeparateFkprincipal

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
public partial class PropertyConfiguration
{

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
public partial class SelfReferencing
{

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
[Table("Test Spaces Keywords Table")]
public partial class TestSpacesKeywordsTable

Просмотреть файл

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace E2ETest.Namespace
namespace E2ETest.Namespace.SubDir
{
[Table("UnmappablePKColumn")]
public partial class UnmappablePkcolumn

Просмотреть файл

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.EntityFrameworkCore.Scaffolding.Internal;
@ -103,8 +104,7 @@ namespace Microsoft.EntityFrameworkCore.ReverseEngineering
var expectedFileSet = new FileSet(new FileSystemFileService(),
Path.Combine("ReverseEngineering", "Expected", "Attributes"),
contents => contents.Replace("namespace " + TestNamespace, "namespace " + TestNamespace + "." + TestSubDir)
.Replace("{{connectionString}}", _connectionString))
contents => contents.Replace("{{connectionString}}", _connectionString))
{
Files = new List<string> { "AttributesContext.cs" }
.Concat(_expectedEntityTypeFiles).ToList()

Просмотреть файл

@ -13,6 +13,7 @@ using Microsoft.EntityFrameworkCore.Scaffolding.Metadata.Internal;
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit;
using Microsoft.EntityFrameworkCore.Utilities;
using Xunit;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore
{
@ -138,14 +139,14 @@ CREATE TABLE [dbo].[Denali] ( id int );";
nonClustered =>
{
Assert.Equal("IX_Location", nonClustered.Name);
Assert.False(nonClustered.SqlServer().IsClustered);
//Assert.False(nonClustered.GetAnnotations().SingleOrDefault(a => a.Name == SqlServerAnnotationNames.Clustered)?.Value);
Assert.Equal("Location", nonClustered.IndexColumns.Select(ic => ic.Column.Name).Single());
},
clusteredIndex =>
{
Assert.Equal("IX_Location_Name", clusteredIndex.Name);
Assert.False(clusteredIndex.IsUnique);
Assert.True(clusteredIndex.SqlServer().IsClustered);
//Assert.True(clusteredIndex.SqlServer().IsClustered);
Assert.Equal(new List<string> { "Location", "Name" }, clusteredIndex.IndexColumns.Select(ic => ic.Column.Name).ToList());
Assert.Equal(new List<int> { 1, 2 }, clusteredIndex.IndexColumns.Select(ic => ic.Ordinal).ToList());
},
@ -153,7 +154,7 @@ CREATE TABLE [dbo].[Denali] ( id int );";
{
Assert.StartsWith("PK__Place", pkIndex.Name);
Assert.True(pkIndex.IsUnique);
Assert.False(pkIndex.SqlServer().IsClustered);
//Assert.False(pkIndex.SqlServer().IsClustered);
Assert.Equal(new List<string> { "Id" }, pkIndex.IndexColumns.Select(ic => ic.Column.Name).ToList());
},
unique =>

Просмотреть файл

@ -1,13 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Reflection;
using Microsoft.EntityFrameworkCore.Scaffolding.Internal;
namespace Microsoft.EntityFrameworkCore
{
public class ApiConsistencyTest : ApiConsistencyTestBase
{
protected override Assembly TargetAssembly => typeof(SqlServerScaffoldingModelFactory).GetTypeInfo().Assembly;
}
}

Просмотреть файл

@ -1,36 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netcoreapp2.0</TargetFrameworks>
<AssemblyName>Microsoft.EntityFrameworkCore.SqlServer.Design.Tests</AssemblyName>
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
</PropertyGroup>
<ItemGroup>
<None Include="..\xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EFCore.Relational.Design.Tests\EFCore.Relational.Design.Tests.csproj" />
<ProjectReference Include="..\EFCore.SqlServer.Design.FunctionalTests\EFCore.SqlServer.Design.FunctionalTests.csproj" />
<ProjectReference Include="..\EFCore.SqlServer.Tests\EFCore.SqlServer.Tests.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Xunit;
namespace Microsoft.EntityFrameworkCore
{
public class SqlServerDesignEventIdTest
{
[Fact]
public void Every_eventId_has_a_logger_method_and_logs_when_level_enabled()
{
var fakeFactories = new Dictionary<Type, Func<object>>
{
{ typeof(string), () => "Fake" }
};
SqlServerTestHelpers.Instance.TestEventLogging(
typeof(SqlServerDesignEventId),
typeof(SqlServerDesignLoggerExtensions),
fakeFactories);
}
}
}

Просмотреть файл

@ -27,7 +27,6 @@
<ItemGroup>
<ProjectReference Include="..\..\src\EFCore.Relational.Specification.Tests\EFCore.Relational.Specification.Tests.csproj" />
<ProjectReference Include="..\..\src\EFCore.SqlServer\EFCore.SqlServer.csproj" />
<ProjectReference Include="..\..\src\EFCore.SqlServer.Design\EFCore.SqlServer.Design.csproj" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -4,6 +4,7 @@
using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Scaffolding.Internal;
using Microsoft.EntityFrameworkCore.Storage.Internal;

Просмотреть файл

@ -23,7 +23,8 @@ namespace Microsoft.EntityFrameworkCore
var fakeFactories = new Dictionary<Type, Func<object>>
{
{ typeof(IProperty), () => property }
{ typeof(IProperty), () => property },
{ typeof(string), () => "Fake" }
};
SqlServerTestHelpers.Instance.TestEventLogging(

Просмотреть файл

@ -22,6 +22,8 @@ namespace E2E.Sqlite
{
modelBuilder.Entity<Comment>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
entity.HasOne(d => d.UserAlt)
.WithMany(p => p.Comment)
.HasPrincipalKey(p => p.AltId)
@ -34,6 +36,8 @@ namespace E2E.Sqlite
entity.HasIndex(e => e.AltId)
.HasName("sqlite_autoindex_User_1")
.IsUnique();
entity.Property(e => e.Id).ValueGeneratedNever();
});
}
}

Просмотреть файл

@ -21,6 +21,16 @@ namespace E2E.Sqlite
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Groups>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
});
modelBuilder.Entity<Users>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
});
modelBuilder.Entity<UsersGroups>(entity =>
{
entity.ToTable("Users_Groups");
@ -29,6 +39,8 @@ namespace E2E.Sqlite
.HasName("sqlite_autoindex_Users_Groups_2")
.IsUnique();
entity.Property(e => e.Id).ValueGeneratedNever();
entity.HasOne(d => d.Group)
.WithMany(p => p.UsersGroups)
.HasForeignKey(d => d.GroupId);

Просмотреть файл

@ -23,6 +23,8 @@ namespace E2E.Sqlite
{
modelBuilder.Entity<Dependent>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
entity.Property(e => e.PrincipalId).HasColumnType("INT");
});
}

Просмотреть файл

@ -26,7 +26,9 @@ namespace E2E.Sqlite
.HasName("sqlite_autoindex_Dependent_1")
.IsUnique();
entity.Property(e => e.Id).HasColumnType("INT");
entity.Property(e => e.Id)
.HasColumnType("INT")
.ValueGeneratedNever();
entity.Property(e => e.PrincipalId).HasColumnType("INT");
@ -35,6 +37,11 @@ namespace E2E.Sqlite
.HasForeignKey<Dependent>(d => d.PrincipalId)
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<Principal>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
});
}
}
}

Просмотреть файл

@ -21,6 +21,8 @@ namespace E2E.Sqlite
{
modelBuilder.Entity<SelfRef>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
entity.HasOne(d => d.SelfForeignKeyNavigation)
.WithMany(p => p.InverseSelfForeignKeyNavigation)
.HasForeignKey(d => d.SelfForeignKey);

Просмотреть файл

@ -22,6 +22,8 @@ namespace E2E.Sqlite
{
modelBuilder.Entity<Comment>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
entity.HasOne(d => d.UserAlt)
.WithMany(p => p.Comment)
.HasPrincipalKey(p => p.AltId)
@ -34,6 +36,8 @@ namespace E2E.Sqlite
entity.HasIndex(e => e.AltId)
.HasName("sqlite_autoindex_User_1")
.IsUnique();
entity.Property(e => e.Id).ValueGeneratedNever();
});
}
}

Просмотреть файл

@ -21,11 +21,23 @@ namespace E2E.Sqlite
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Groups>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
});
modelBuilder.Entity<Users>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
});
modelBuilder.Entity<UsersGroups>(entity =>
{
entity.HasIndex(e => new { e.UserId, e.GroupId })
.HasName("sqlite_autoindex_Users_Groups_2")
.IsUnique();
entity.Property(e => e.Id).ValueGeneratedNever();
});
}
}

Просмотреть файл

@ -20,6 +20,11 @@ namespace E2E.Sqlite
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{}
{
modelBuilder.Entity<Dependent>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
});
}
}
}

Просмотреть файл

@ -26,11 +26,18 @@ namespace E2E.Sqlite
.HasName("sqlite_autoindex_Dependent_1")
.IsUnique();
entity.Property(e => e.Id).ValueGeneratedNever();
entity.HasOne(d => d.Principal)
.WithOne(p => p.Dependent)
.HasForeignKey<Dependent>(d => d.PrincipalId)
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<Principal>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
});
}
}
}

Просмотреть файл

@ -18,6 +18,11 @@ namespace E2E.Sqlite
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{}
{
modelBuilder.Entity<SelfRef>(entity =>
{
entity.Property(e => e.Id).ValueGeneratedNever();
});
}
}
}