0

I have a simple query to a DBSet which is giving a typing error. When i debug it gives the following error: "The 'TranNumber' property on 'InventoryAdjustment' could not be set to a 'System.String' value. You must set this property to a non-null value of type 'System.Int32'. ". Here is the code of the query:

var filter = DataContext.InventoryAdjustments.Where(x => x.RecStatus == 0 || x.RecStatus == 4).AsQueryable();

And the declaration of the field in the entity which is filtered:

[Column("TranNumber")]
 public int TransactionNumber { get; set; }

Since "filter" is an anonymous variable, i don't understand which is the mapping problem to result in that error.

javier_el_bene
  • 450
  • 2
  • 10
  • 25
  • What is the type for TranNumber in the actual database? – ohiodoug Dec 28 '15 at 15:07
  • The type of the TranNumber column in the database is nvarchar. I thought it could be the problem but that entity is involved in other processes of the system without any problem. – javier_el_bene Dec 28 '15 at 15:13
  • That's likely your problem. It's trying to map a nvarchar field (string) to an integer field. – ohiodoug Dec 28 '15 at 15:20
  • Ok. I'll check if that change doesn't affect other module of the system. Thanks. – javier_el_bene Dec 28 '15 at 15:21
  • 1
    Keep in mind that your changes don't necessarily HAVE to be in the database. You could change your model instead so that TransactionNumber is a string rather than an int. That will also likely solve your query problem and then you can adjust the value accordingly in your C# code. Not a perfect solution in the long-run, but it's another approach. – ohiodoug Dec 28 '15 at 15:36
  • You are right ohiodoug. But in any case, i have to analyze both solutions because changing the model infrastructure in this case looks pretty messy too. Thanks again. – javier_el_bene Dec 28 '15 at 15:41
  • Absolutely. That's why I offered up the alternate solution -- it might have less consequences. I don't envy the day you are about to have. Good luck! =) – ohiodoug Dec 28 '15 at 15:42

0 Answers0