You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed whilst profiling recently that I keep getting random calls to update particular entities when I flush changes to the database, even if they haven't changed.
After looking into this further, i've discovered this seems to happen when the entity has a dynamic component with nullable properties.
For example, say I have the following application:
Here's the SQL to setup the database table with some sample data:
CREATE TABLE [dbo].[Products](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[Sku] [nvarchar](50) NULL,
CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED ([Id] ASC)
)
INSERT INTO [dbo].[Products] ([Name], [Sku]) VALUES ('Test 1', NULL)
INSERT INTO [dbo].[Products] ([Name], [Sku]) VALUES ('Test 2', 'ABC')
INSERT INTO [dbo].[Products] ([Name], [Sku]) VALUES ('Test 3', NULL)
Now when profiling the application, notice how it will issue 2 updates (only the products where the Sku is null) to the database when you flush the changes.
This seems like a bug to me but I thought I'd check before creating a test case.
I have discovered that this isn't an issue if I change my Attributes property to the following:
However this will still set the Attributes to null against the products where all the values of the Attributes are null and will likely lead to much bigger problems.
The text was updated successfully, but these errors were encountered:
nfplee
changed the title
Dynamic component with nullable property always causes a update on flush
Dynamic component with nullable property always causes an update on flush
Aug 30, 2023
However this will still set the Attributes to null against the products where all the values of the Attributes are null and will likely lead to much bigger problems.
I used an SqlInterceptor to monitor the queries sent to the database. The test confirms that when flushing changes it will trigger an update for any entity where all the values are null against a dynamic component, even if it hasn't changed.
I've noticed whilst profiling recently that I keep getting random calls to update particular entities when I flush changes to the database, even if they haven't changed.
After looking into this further, i've discovered this seems to happen when the entity has a dynamic component with nullable properties.
For example, say I have the following application:
With the following model and mapping:
Here's the SQL to setup the database table with some sample data:
Now when profiling the application, notice how it will issue 2 updates (only the products where the
Sku
is null) to the database when you flush the changes.This seems like a bug to me but I thought I'd check before creating a test case.
I have discovered that this isn't an issue if I change my
Attributes
property to the following:However this will still set the
Attributes
to null against the products where all the values of theAttributes
are null and will likely lead to much bigger problems.The text was updated successfully, but these errors were encountered: