3

I am working with a DB-first entity framework application. Using SQL Server as the DB, which does not have unsigned column types. Is it possible when generating the model from the DB to cause EF to map fields to uint instead of int? (The tables are based on external structures, and most of the fields are uint. As it stands now, I have to cast all the fields to int in order to work with EF.)

I believe this is different than How to use unsigned int / long types with Entity Framework? because I am talking about mapping in a DB-first environment, which is different from what they did there. Also, I am trying to avoid casting, if possible.

Community
  • 1
  • 1
Eli
  • 693
  • 5
  • 12
  • 2
    possible duplicate of [How to use unsigned int / long types with Entity Framework?](http://stackoverflow.com/questions/26303631/how-to-use-unsigned-int-long-types-with-entity-framework) – Hintham Apr 13 '15 at 07:30

2 Answers2

4

Unsigned types are not supported by EF.

Source: https://entityframework.codeplex.com/workitem/1489

From what I can tell there's not going to be an alternative to explicit casting. Unsigned casting is strictly enforced by C#, and conversion between the types has a possible loss of information when it comes to negative or large vales. My only suggestion is to implement a helper or extension method to perform the cast that has built in error checking.

Jason
  • 506
  • 3
  • 14
  • 1
    Thanks. I was afraid of this, but had a small hope of finding that there was some way to do what I wanted... – Eli Apr 14 '15 at 09:10
0

How to use unsigned int / long types with Entity Framework?

Check this out. Basically it's using signed data type in the database but using unchecked casting to convert signed to unsiged in C#.

Community
  • 1
  • 1
fjch1997
  • 1,518
  • 18
  • 19
  • This should be a comment, not an answer. If it is a duplicate question then [vote to close](http://stackoverflow.com/help/privileges/close-questions) as such and/or leave a comment once you [earn](http://meta.stackoverflow.com/q/146472) enough [reputation](http://stackoverflow.com/help/whats-reputation). If the question is not a duplicate then tailor the answer to this specific question. – Petter Friberg Nov 05 '16 at 21:57