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

Insert not reflecting correct datatypes #7704

Closed
Tasteful opened this issue Feb 24, 2017 · 2 comments
Closed

Insert not reflecting correct datatypes #7704

Tasteful opened this issue Feb 24, 2017 · 2 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@Tasteful
Copy link
Contributor

Table that is created by EF Migration

CREATE TABLE [Products].[BaseProductFieldData](
	[OwnerSystemId] [uniqueidentifier] NOT NULL,
	[FieldDefinitionId] [nvarchar](100) NOT NULL,
	[Culture] [nvarchar](10) NOT NULL,
	[Index] [int] NOT NULL,
	[BooleanValue] [bit] NULL,
	[DateTimeValue] [datetimeoffset](7) NULL,
	[DecimalValue] [decimal](18, 2) NULL,
	[GuidValue] [uniqueidentifier] NULL,
	[IndexedTextValue] [nvarchar](250) NULL,
	[IntValue] [int] NULL,
	[JsonValue] [nvarchar](max) NULL,
	[TextValue] [nvarchar](max) NULL,
	[LongValue] [bigint] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

Generated SQL Insert from SQL Profiler

exec sp_executesql N'SET NOCOUNT ON;
INSERT INTO [Products].[BaseProductFieldData] ([OwnerSystemId], [FieldDefinitionId], [Culture], [Index], [BooleanValue], [DateTimeValue], [DecimalValue], [GuidValue], [IndexedTextValue], [IntValue], [JsonValue], [LongValue], [TextValue])
VALUES (@p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18);',
N'@p6 uniqueidentifier,@p7 nvarchar(100),@p8 nvarchar(10),@p9 int,@p10 nvarchar(4000),@p11 nvarchar(4000),@p12 nvarchar(4000),@p13 nvarchar(4000),@p14 nvarchar(250),@p15 int,@p16 nvarchar(4000),@p17 bigint,@p18 nvarchar(4000)',
@p6='09AE36A4-6146-4838-9617-533F8E7C0406',@p7=N'FieldDefinition0',@p8=N'aa-DJ',@p9=0,@p10=NULL,@p11=NULL,@p12=NULL,@p13=NULL,@p14=NULL,@p15=NULL,@p16=NULL,@p17=NULL,@p18=N'4c6b5aba-6427-4f07-9753-7c831dbf788e',@p19='D5343606-E6B7-4CC6-93E3-89F7321703E2',@p20='09AE36A4-6146-4838-9617-533F8E7C0406'

If we check the parameter types and compare them to the datatype that the table is specified with, check @p10 to @P13. What is the reason to use nvarchar(4000) for a nullable bit field?

@p6 uniqueidentifier, -- [OwnerSystemId] [uniqueidentifier] NOT NULL,
@p7 nvarchar(100), -- [FieldDefinitionId] [nvarchar](100) NOT NULL,
@p8 nvarchar(10), -- [Culture] [nvarchar](10) NOT NULL,
@p9 int, -- [Index] [int] NOT NULL,
@p10 nvarchar(4000), -- [BooleanValue] [bit] NULL,
@p11 nvarchar(4000), -- [DateTimeValue] [datetimeoffset](7) NULL,
@p12 nvarchar(4000), -- [DecimalValue] [decimal](18, 2) NULL,
@p13 nvarchar(4000), -- [GuidValue] [uniqueidentifier] NULL,
@p14 nvarchar(250), -- [IndexedTextValue] [nvarchar](250) NULL,
@p15 int, -- [IntValue] [int] NULL,
@p16 nvarchar(4000), -- [JsonValue] [nvarchar](max) NULL,
@p17 bigint, -- [LongValue] [bigint] NULL
@p18 nvarchar(4000) -- [TextValue] [nvarchar](max) NULL,

Further technical details

EF Core version: 1.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2015

@ajcvickers
Copy link
Member

Note for triage: this happens when the value of a parameter is null. We create a default type mapping which ultimately ends up looking like nvarchar(4000). The correct mapping for the type is used for any non-null value.

@rowanmiller rowanmiller added this to the 2.0.0 milestone Feb 24, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Apr 19, 2017
@ajcvickers
Copy link
Member

Verified that for 2.0, we don't set Size for these parameter types, and that when we do set DbType it is set to the correct value.

@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants