Linq to SQL Int16 get converted as Int32 to SQL command
With method parameter
Int16? id
And the Linq to SQL where where clause
where !id.HasValue || m.Id == id
Received command text for condition in data context
From the renderer:
SELECT [t0].[Id], [t0].[Name], [t0].[IsActive]
FROM [Model] AS [t0]
WHERE (CONVERT(Int,[t0].[Id])) = @p0
-------------------------------
@p0 [Int32]: 5
My mapped class has id as Int16 and the database itself has column type as small, so why behind the scenes does sql think this parameter is an integer (Int32) and not a small (Int16)?
Column display:
[Column(IsPrimaryKey = true, DbType="SmallInt NOT NULL", CanBeNull=false)]
public Int16 Id { get; set; }
Modify where clause to read
where !id.HasValue || m.Id == id.Value
There is something about zero short that discards it. I'm not sure why, but I ran into this before and found the addition .Value
would work.
Hmmm ... I notice you are not getting any representation of id.HasValue in sql. Perhaps this is some kind of deception related to the fact that he turned around? Seems feigned to me, but the only thing I can think of.