2

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

2 Answers2

6

int and Int32 are the same type. No cast is necessary.

Edit

If your column is a smallint, that corresponds to an Int16 (or short using the C# keyword). You can either use the CONVERT statement as you are now, or you can change the property on your object to be a short.

Adam Robinson
  • 182,639
  • 35
  • 285
  • 343
  • Thx for this. Just looked at the exceptiona again, made a mistake - SQL attribute is of type smallint when my property is of type int. –  Sep 10 '10 at 12:32
  • Yea the SQL convert has fixed the issue. THank you –  Sep 10 '10 at 14:23
0

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