Why is Entity Framework passing a parameter as DECIMAL(5,0) for a column defined with NUMERIC(19)?

后端 未结 1 1439
南旧
南旧 2021-01-22 21:41

A database column is defined as NUMERIC(19) in SQL Server. In , the edmx shows:



        
1条回答
  •  一整个雨季
    2021-01-22 22:13

    (@p__linq__0 decimal(5,0)) is the Precision of the parameter value your provided.

    For example,

    decimal number = 12345m;
    var result = context.MyTables.Where(x => x.Number == number).ToList();
    

    Then the query will be like this -

    exec sp_executesql N'SELECT 
        [Extent1].[Id] AS [Id], 
        [Extent1].[Number] AS [Number]
        FROM [dbo].[MyTable] AS [Extent1]
        WHERE [Extent1].[Number] = @p__linq__0',N'@p__linq__0 decimal(5,0)',
        @p__linq__0=12345
    

    The answer is SQL Statement doesn't need to be same Precision number for where clause.

    Entity Framework is smart enough to figure out the Precision of a number, and only creates the query with required Precision.

    Note: it is not the case for Insert and Update; EF creates a query with the same Precision as Column.

    0 讨论(0)
提交回复
热议问题