none
Enity Framework Code first AddOrUpdate bug RRS feed

All replies

  • Hi,

    Have you tried to use SQL Server Profiler to see what SQL statements are sent to the db to check for already existing data ? It could perhaps help to figure out what happens (I don"t have any idea for now).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Wednesday, April 4, 2012 10:55 AM
  • First call of Update-Database:

    SELECT TOP (2) [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name] FROM [dbo].[Hall] AS [Extent1] WHERE N'French' = [Extent1].[Name]
    
    SELECT TOP (2) [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name] FROM [dbo].[Hall] AS [Extent1] WHERE N'German' = [Extent1].[Name]
    
    SELECT TOP (2) [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name]FROM [dbo].[Hall] AS [Extent1] WHERE N'Japaneese' = [Extent1].[Name]
    
    exec sp_executesql N'insert [dbo].[Hall]([Name]) values (@0) select [Id] from [dbo].[Hall] where @@ROWCOUNT > 0 and [Id] = scope_identity()', N'@0 varchar(max) ',@0=N'French'
    
    exec sp_executesql N'insert [dbo].[Hall]([Name]) values (@0) select [Id] from [dbo].[Hall] where @@ROWCOUNT > 0 and [Id] = scope_identity()', N'@0 varchar(max) ',@0=N'Japaneese'
    
    exec sp_executesql N'insert [dbo].[Hall]([Name]) values (@0) select [Id] from [dbo].[Hall] where @@ROWCOUNT > 0 and [Id] = scope_identity()', N'@0 varchar(max) ',@0=N'German'

    Next call of Update-Database:

    SELECT TOP (2) [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name] FROM [dbo].[Hall] AS [Extent1] WHERE N'French' = [Extent1].[Name]
    	
    SELECT TOP (2) [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name] FROM [dbo].[Hall] AS [Extent1] WHERE N'German' = [Extent1].[Name]
    
    SELECT TOP (2) [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name] FROM [dbo].[Hall] AS [Extent1] WHERE N'Japaneese' = [Extent1].[Name]
    
    exec sp_executesql N'insert [dbo].[Hall]([Name]) values (@0) select [Id] from [dbo].[Hall] where @@ROWCOUNT > 0 and [Id] = scope_identity()',N'@0 nvarchar(max) ',@0=N'French'
    
    exec sp_executesql N'insert [dbo].[Hall]([Name]) values (@0) select [Id] from [dbo].[Hall] where @@ROWCOUNT > 0 and [Id] = scope_identity()',N'@0 nvarchar(max) ',@0=N'Japaneese'
    

    Wednesday, April 4, 2012 1:42 PM
  • I noticed here and from your StackOverflow post that it seems the problem occurs for French and Japanese but doesn't seems to happen for German ??? Is this right or did you ommit inadvertently the German insert statement ?

    Looks really weird. I would try with a stringlength rather to let nvarchar(max) even though I don't see what difference it can make. Just a shot in the dark. I'll try later to see if I have the same issue with AddOrUpdate here...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Wednesday, April 4, 2012 2:58 PM
  • "I noticed here and from your StackOverflow post that it seems the problem occurs for French and Japanese but doesn't seems to happen for German ??? Is this right or did you ommit inadvertently the German insert statement ?"

    Yes it's true. It's very strange for me too.

    UPDATE:

    I tried other words for name - the same issue:

    Id Name
    1 One
    2 Three
    3 Two
    4 One
    5 Three


    Wednesday, April 4, 2012 4:38 PM