views:

55

answers:

2

Hi,

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

+5  A: 

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
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.
vikp
@vikp: See if my edit addressed your issue.
Adam Robinson
Yea the SQL convert has fixed the issue. THank you
vikp
A: 

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

vikp