With the method parameter
Int16? id
And the Linq to SQL where clause
where !id.HasValue || m.Id == id
The resulting command text for the condition in the data context is
From the visualizer:
SELECT [t0].[Id], [t0].[Name], [t0].[IsActive]
FROM [Model] AS [t0]
WHERE (CONVERT(Int,[t0].[Id])) = @p0
-------------------------------
@p0 [Int32]: 5
My mapped class has the Id as an Int16 and the database itself has the column type as a smallint, so why does the behind the scenes sql think the parameter is an integer (Int32) and not a smallint (Int16)?
Column mapping:
[Column(IsPrimaryKey = true, DbType="SmallInt NOT NULL", CanBeNull=false)]
public Int16 Id { get; set; }