Thursday, September 29, 2011

Linq Error - Specified cast is not valid

I was getting this error in the selecting event.  The problem was that for whatever reason, a field in the the LinqToSql file had a different datatype from the actual table in the database.  The field in the table was of type bigint while the same field in the datacontext was of type int.  This could have happened if for example the database schema was altered after having dropped the table in the LinqToSQL file.  Removing the table from the datacontext and re-dropping it solved the issue.

Anyone know how to refresh the LinqToSQL file without having to remove the table and reinserting it?  That would be great!

1 comment:

  1. I think you can update the definitions from visual studio 2010. Just right click in the LINQ diagram and click on update.

    PS: you're a commercial organisation now? :P