开发者

LinqToSql giving 'Specified cast is not valid'

开发者 https://www.devze.com 2022-12-09 15:44 出处:网络
I\'m running a stored procedure through L2S and it\'s returning \'Specified cast is not valid\'. The stored proc is returning data when ran manually and when I step thru it, everything is fine until i

I'm running a stored procedure through L2S and it's returning 'Specified cast is not valid'. The stored proc is returning data when ran manually and when I step thru it, everything is fine until it tries to create the row object in "foreach (var row in result)".

var q = new db();
var result = q.GetNearbyLocations(latitude, longitude,searchDistance);
foreach (var row in result)
   {
      var c = new Clinic()
                {
                   Name = row.CLINIC_NAME.Trim(),
                   Ad开发者_开发技巧dress1 = row.DRADR1.Trim()...

Ideas?


That is usually caused by a data type mismatch, e.g. if the stored procedure returns a int and that is mapped to a string, or if the stored proc return a varchar(1) and that is mapped to a System.Char.


Your sporc isn't actually invoked until a foreach statement is executed. Therefore, ensure that LINQ to SQL can correctly map data returned from the sproc to your objects.

0

精彩评论

暂无评论...
验证码 换一张
取 消