Skip to content

Commit

Permalink
Make DatabaseGeneratedOption.Identity attribute just set ValueGenerat…
Browse files Browse the repository at this point in the history
…ed to OnAdd on SQL Server

Part of dotnet#7010
  • Loading branch information
AndriySvyryd committed Dec 16, 2016
1 parent 6b4539b commit a02a339
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ public virtual ModelBuilder DatabaseGeneratedOption_configures_the_property_corr

var identity = entity.FindProperty(nameof(GeneratedEntity.Identity));
Assert.Equal(ValueGenerated.OnAdd, identity.ValueGenerated);
Assert.False(identity.RequiresValueGenerator);

var version = entity.FindProperty(nameof(GeneratedEntity.Version));
Assert.Equal(ValueGenerated.OnAddOrUpdate, version.ValueGenerated);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
// 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.Metadata.Internal;
using System.ComponentModel.DataAnnotations.Schema;

namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.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 SqlServerValueGenerationStrategyConvention : DatabaseGeneratedAttributeConvention, IModelConvention
public class SqlServerValueGenerationStrategyConvention : IModelConvention
{
public override InternalPropertyBuilder Apply(
InternalPropertyBuilder propertyBuilder, DatabaseGeneratedAttribute attribute, MemberInfo clrMember)
{
propertyBuilder.SqlServer(ConfigurationSource.DataAnnotation).ValueGenerationStrategy(
attribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity
? SqlServerValueGenerationStrategy.IdentityColumn
: (SqlServerValueGenerationStrategy?)null);

return base.Apply(propertyBuilder, attribute, clrMember);
}

/// <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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ public override ConventionSet AddConventions(ConventionSet conventionSet)
var valueGenerationStrategyConvention = new SqlServerValueGenerationStrategyConvention();
conventionSet.ModelInitializedConventions.Add(valueGenerationStrategyConvention);

ReplaceConvention(conventionSet.PropertyAddedConventions, (DatabaseGeneratedAttributeConvention)valueGenerationStrategyConvention);

var sqlServerInMemoryTablesConvention = new SqlServerMemoryOptimizedTablesConvention();
conventionSet.EntityTypeAnnotationSetConventions.Add(sqlServerInMemoryTablesConvention);

conventionSet.KeyAddedConventions.Add(sqlServerInMemoryTablesConvention);

conventionSet.IndexAddedConventions.Add(sqlServerInMemoryTablesConvention);

ReplaceConvention(conventionSet.PropertyFieldChangedConventions, (DatabaseGeneratedAttributeConvention)valueGenerationStrategyConvention);

return conventionSet;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ public DataAnnotationInMemoryTest(DataAnnotationInMemoryFixture fixture)
{
}

public override ModelBuilder DatabaseGeneratedOption_configures_the_property_correctly()
{
var modelBuilder = base.DatabaseGeneratedOption_configures_the_property_correctly();

var identity = modelBuilder.Model.FindEntityType(typeof(GeneratedEntity)).FindProperty(nameof(GeneratedEntity.Identity));
Assert.False(identity.RequiresValueGenerator);

return modelBuilder;
}

public override void ConcurrencyCheckAttribute_throws_if_value_in_database_changed()
{
using (var context = CreateContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Specification.Tests;
using Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.Utilities;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -95,17 +94,6 @@ public override ModelBuilder TableNameAttribute_affects_table_name_in_TPH()
return modelBuilder;
}

public override ModelBuilder DatabaseGeneratedOption_configures_the_property_correctly()
{
var modelBuilder = base.DatabaseGeneratedOption_configures_the_property_correctly();

var identity = modelBuilder.Model.FindEntityType(typeof(GeneratedEntity)).FindProperty(nameof(GeneratedEntity.Identity));
Assert.True(identity.RequiresValueGenerator);
Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, identity.SqlServer().ValueGenerationStrategy);

return modelBuilder;
}

public override void ConcurrencyCheckAttribute_throws_if_value_in_database_changed()
{
base.ConcurrencyCheckAttribute_throws_if_value_in_database_changed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ public override ModelBuilder TableNameAttribute_affects_table_name_in_TPH()
return modelBuilder;
}

public override ModelBuilder DatabaseGeneratedOption_configures_the_property_correctly()
{
var modelBuilder = base.DatabaseGeneratedOption_configures_the_property_correctly();

var identity = modelBuilder.Model.FindEntityType(typeof(GeneratedEntity)).FindProperty(nameof(GeneratedEntity.Identity));
Assert.False(identity.RequiresValueGenerator);

return modelBuilder;
}

public override void ConcurrencyCheckAttribute_throws_if_value_in_database_changed()
{
base.ConcurrencyCheckAttribute_throws_if_value_in_database_changed();
Expand Down

0 comments on commit a02a339

Please sign in to comment.