如何在 SQL 选择期间通过 LINQ 数据上下文将 INT32 转换为 INT?
我有以下语句:
someList = dc.ExecuteQuery<MyCustomType>(@"Select Id As ProductId, Name From ivProduct").ToList();
当我的MyCustomType的Id属性为INT时,数据库中的Id存储为int32。有没有办法在选择期间将 int32 转换为 int ?
谢谢
I have the following statement:
someList = dc.ExecuteQuery<MyCustomType>(@"Select Id As ProductId, Name From ivProduct").ToList();
Id in the database is stored as int32, when my Id property of MyCustomType is INT. Is there a way to cast that int32 to int during a select?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
int
和Int32
是相同的类型。无需演员阵容。编辑
如果您的列是
smallint
,则对应于Int16
(或使用 C# 关键字的short
)。您可以像现在一样使用CONVERT
语句,也可以将对象上的属性更改为short
。int
andInt32
are the same type. No cast is necessary.Edit
If your column is a
smallint
, that corresponds to anInt16
(orshort
using the C# keyword). You can either use theCONVERT
statement as you are now, or you can change the property on your object to be ashort
.执行
Convert(INT,Id) As ProductId
完成了这项工作。如果能找到一种无需 SQL Convert 即可实现的方法,那就太好了。可能会尝试将强制转换添加到属性中Doing
Convert(INT,Id) As ProductId
did the job. Would be good to see a way to do it without SQL Convert. Might try adding cast to properties