Skip to content

HasKey and ValueGeneratedOnAdd have a declaration order dependency #5776

@alexandru-calinoiu

Description

@alexandru-calinoiu

Steps to reproduce

PropertyClassEntity

    public class PropertyClassEntity
    {
        public override PropertyClassEntityTypeEnum Id { get; set; }
    }

PropertyEntity.cs

    public sealed class PropertyEntity : Entity
    {
        public PropertyClassEntity PropertyClass { get; set; }
    }

PropertyClassEntityTypeEnum

    public enum PropertyClassEntityTypeEnum : byte
    {
        A = 1,
        B,
        C
    }

CommonMapping (works)

            builder.Property(t => t.Id).ValueGeneratedOnAdd();
            builder.HasKey(t => t.Id);

CommonMapping (does not work)

            builder.HasKey(t => t.Id);
            builder.Property(t => t.Id).ValueGeneratedOnAdd();

The issue

When trying to save the PropertyEntity it will throw the following error:

Result Message: The property 'Id' on entity type 'PropertyClassEntity' has a temporary value while attempting to change the entity's state to 'Unchanged'. Either set a permanent value explicitly or ensure that the database is configured to generate values for this property.

Further technical details

EF Core version: 1.0.0-rc2-final
Operating system: Win10
Visual Studio version: VS 2015

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions