forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation for unique column names
Showing
21 changed files
with
184 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/EntityFramework.MicrosoftSqlServer/Internal/SqlServerModelValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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.Data.Entity.Metadata; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Data.Entity.Internal | ||
{ | ||
public class SqlServerModelValidator : RelationalModelValidator | ||
{ | ||
public SqlServerModelValidator([NotNull] ILogger<RelationalModelValidator> loggerFactory, [NotNull] IRelationalAnnotationProvider relationalExtensions) | ||
: base(loggerFactory, relationalExtensions) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/EntityFramework.Relational/Properties/RelationalStrings.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/EntityFramework.Sqlite/Infrastructure/Internal/SqliteModelValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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.Data.Entity.Internal; | ||
using Microsoft.Data.Entity.Metadata; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Data.Entity.Infrastructure.Internal | ||
{ | ||
public class SqliteModelValidator : RelationalModelValidator | ||
{ | ||
public SqliteModelValidator([NotNull] ILogger<RelationalModelValidator> loggerFactory, [NotNull] IRelationalAnnotationProvider relationalExtensions) | ||
: base(loggerFactory, relationalExtensions) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
test/EntityFramework.MicrosoftSqlServer.Tests/SqlServerModelValidatorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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.Data.Entity.Internal; | ||
using Microsoft.Data.Entity.Metadata; | ||
using Microsoft.Data.Entity.Metadata.Conventions.Internal; | ||
using Microsoft.Data.Entity.Tests; | ||
using Microsoft.Data.Entity.Tests.TestUtilities; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Data.Entity.SqlServer.Tests | ||
{ | ||
public class SqlServerModelValidatorTest : RelationalModelValidatorTest | ||
{ | ||
public override void Detects_duplicate_column_names() | ||
{ | ||
var modelBuilder = new ModelBuilder(new CoreConventionSetBuilder().CreateConventionSet()); | ||
modelBuilder.Entity<Product>(); | ||
modelBuilder.Entity<Product>().Property(b => b.Name).ForSqlServerHasColumnName("Id"); | ||
|
||
VerifyError(RelationalStrings.DuplicateColumnName("Id", typeof(Product).FullName, "Name"), modelBuilder.Model); | ||
} | ||
|
||
private class Product | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
|
||
protected override ModelValidator CreateModelValidator() | ||
=> new SqlServerModelValidator( | ||
new Logger<SqlServerModelValidator>( | ||
new ListLoggerFactory(Log, l => l == typeof(SqlServerModelValidator).FullName)), | ||
new TestSqlServerAnnotationProvider()); | ||
} | ||
|
||
public class TestSqlServerAnnotationProvider : TestAnnotationProvider | ||
{ | ||
public override IRelationalPropertyAnnotations For(IProperty property) => new SqlServerPropertyAnnotations(property); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/EntityFramework.Sqlite.Tests/SqliteModelValidatorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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.Data.Entity.Infrastructure.Internal; | ||
using Microsoft.Data.Entity.Internal; | ||
using Microsoft.Data.Entity.Metadata; | ||
using Microsoft.Data.Entity.Metadata.Conventions.Internal; | ||
using Microsoft.Data.Entity.Metadata.Internal; | ||
using Microsoft.Data.Entity.Tests; | ||
using Microsoft.Data.Entity.Tests.TestUtilities; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Data.Entity.Sqlite.Tests | ||
{ | ||
public class SqliteModelValidatorTest : RelationalModelValidatorTest | ||
{ | ||
public override void Detects_duplicate_column_names() | ||
{ | ||
var modelBuilder = new ModelBuilder(new CoreConventionSetBuilder().CreateConventionSet()); | ||
modelBuilder.Entity<Product>(); | ||
modelBuilder.Entity<Product>().Property(b => b.Name).ForSqliteHasColumnName("Id"); | ||
|
||
VerifyError(RelationalStrings.DuplicateColumnName("Id", typeof(Product).FullName, "Name"), modelBuilder.Model); | ||
} | ||
|
||
private class Product | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
|
||
protected override ModelValidator CreateModelValidator() | ||
=> new SqliteModelValidator( | ||
new Logger<SqliteModelValidator>( | ||
new ListLoggerFactory(Log, l => l == typeof(SqliteModelValidator).FullName)), | ||
new TestSqliteAnnotationProvider()); | ||
} | ||
|
||
public class TestSqliteAnnotationProvider : TestAnnotationProvider | ||
{ | ||
public override IRelationalPropertyAnnotations For(IProperty property) => new RelationalPropertyAnnotations(property, SqliteAnnotationNames.Prefix); | ||
} | ||
} |