Page 1 of 1

var result type problem

Posted: Thu 27 Aug 2009 13:01
by billh
Hello!!

I have the following code...

int convertedId = Int32.Parse(id);

var res = from p in rms_cntxt.Rms
where p.RmsNbr == convertedId
select p;

return View("Edit", res);

The consumer of this return 'res' results in this error

The model item passed into the dictionary is of type 'Devart.Data.Linq.DataQuery`1[RMS1.Rms]' but this dictionary requires a model item of type 'RMS1.Rms'.

Changing the 'var' to 'Rms' does not fix things - that results in

Cannot implicitly convert type 'System.Linq.IQueryable' to
'RMS1.Rms'. An explicit conversion exists (are you missing a cast?).


So I don't know how to fix this - hoping for suggestions.
Thanks, Bill

Posted: Thu 27 Aug 2009 19:58
by billh
Changed return View("Edit", res);

To

return View("Edit, res.First());

So now I am wondering if this hack is ok.
I am still confused as to whether 'res' is an object or array of objects, or what.

Thanks,
Bill

Posted: Tue 01 Sep 2009 12:03
by Shalex
res is a collection, res.First() is its first element. There is no definition for the View class, so we cannot provide you the exact code. Please refer to MSDN to get the description of the LINQ language.