Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF ignores ValueGeneratedOnAdd #13592

Closed
msmolka opened this issue Oct 11, 2018 · 1 comment
Closed

EF ignores ValueGeneratedOnAdd #13592

msmolka opened this issue Oct 11, 2018 · 1 comment

Comments

@msmolka
Copy link

msmolka commented Oct 11, 2018

Describe what is not working as expected.

Steps to reproduce

I have following model

public class Area
{        
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public DateTimeOffset CreatedDate { get; set; }

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid Id { get; set; }
       
        public string Name { get; set; }
}

I've even added manually:

builder.Entity<Area>().Property(r => r.Id).ValueGeneratedOnAdd();

The query generated by EF is:

exec sp_executesql N'SET NOCOUNT ON;
INSERT INTO [Job].[Area] ([Id], [Name])
VALUES (@p0, @p1);
SELECT [CreatedDate]
FROM [Job].[Area]
WHERE @@ROWCOUNT = 1 AND [Id] = @p0;

',N'@p0 uniqueidentifier,@p1 nvarchar(4000)',@p0='0E466D42-ED59-4023-6E49-08D62F701EBE',@p1=N'test'

I would expect that Id will be generated by server. but it is inserted.

Further technical details

EF Core version: 2.1.4
Database Provider: (Microsoft.EntityFrameworkCore.SqlServer)
Operating system: Windows 10 Pro
IDE: (e.g. Visual Studio 2017 15.8.7)

@ajcvickers
Copy link
Member

@msmolka See my answer here: #10070 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants