问题描述
使用方法参数
Int16的? ID
而LINQ to SQL的where子句
在哪里!id.HasValue || m.Id ==编号
在数据上下文的条件将所得命令文本是对>
从可视化:
SELECT [T0] [ID],[。 T0]。[名],[T0]。[IsActive]
从[产品型号] AS [T0]
WHERE(CONVERT(智力,[T0]。[ID]))= @ P0
-------------------------------
@ P0 [的Int32]:5
我的映射类具有ID作为Int16的和本身所具有的列类型为SMALLINT数据库中,那么,为什么后面的场景sql中认为参数是一个整数(Int32)已而不是SMALLINT(Int16的)?
列映射:
[列(IsPrimaryKey =真,的DbType =SMALLINT NOT NULL,CanBeNull = FALSE)]
公众的Int16标识{搞定;组; }
更改where子句来读
在哪里!id.HasValue || m.Id == id.Value
有一些是关于是把它扔了可空做空。我不知道为什么,但我之前就遇到了这个发现将 .value的
将工作。
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; }
Change the where clause to read
where !id.HasValue || m.Id == id.Value
There is something about the nullable short that is throwing it off. I'm not sure why, but I ran into this before and found adding .Value
will work.
这篇关于LINQ到SQL的Int16被转换为的Int32在SQL命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!