简体   繁体   中英

How to map tinyint to int?

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.)

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM