c# - "Specified cast is not valid" error in LINQ's orderby clause -


i doing right join between 2 datatables in linq. getting error @ orderby line ""specified cast not valid".

"someotherid" column of type system.int64 in dbml , allows dbnull. column has null values in data, valid. seems these nulls have handled in way in orderby statement not sure how. data coming in through web service. checked reference.cs file , corresponding property column int.

how should linq statement be?

 var query = (from table1 in datatable1.asenumerable()                           join table2 in datatable2.asenumerable()                               on (int) table1["customerid"] equals (int) table2["customerid"] outer                           table2 in outer.defaultifempty()                           orderby (int?)table2["someotherid"]                            select new                                      {                                          ......                                      }); 

also check : linq: orderby nullable columns in typeddatasets

try below way

var query =  (from table1 in datatable1.asenumerable()   join table2 in datatable2.asenumerable()   on (int) table1["customerid"] equals (int) table2["customerid"]     outer table2 in outer.defaultifempty() //order clause changed here       orderby     (convert.isdbnull(table2["someotherid"]) ? 0 : (int?)                           convert.toint32(table2["someotherid"]))     select new        {            ......        }); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -