开发者

How to map tinyint to int?

开发者 https://www.devze.com 2023-03-25 03:28 出处:网络
I have about a dozen fields marked as tinyint, which translates to a byte field. I\'m finding that I\'m having to do a lot of casting to int in my code to interact with integers.

I have about a dozen fields marked as tinyint, which translates to a byte field. I'm finding that I'm having to do a lot of casting to int in my code to interact with integers.

Because of this, I'm thinking of changing the entity framework to read these as integers instead of bytes. Are there any implications of this, besides the chance that I may pass in an integer that is out of range of the tinyint? Am I just adding additional casts where I may not need them?

(I'm also thinking of just using integer instead in the database, because this isn't going to be a high usage DB.)

Edit

From Zach's comment below / Entity Framework Mapping SQL Server tinyint to Int16 -- it looks like I can't just change the property from byte开发者_StackOverflow中文版 to int? The EF will throw an error? So, is there even a way to do what I'm thinking?


There shouldn't really be any issue using when you use Integers as the compiler actually optimizes the integers (I'm not mistaken.)

The best bet would be to change your database values from byte to Int. IMHO.

0

精彩评论

暂无评论...
验证码 换一张
取 消