Is possible to write a query like below using LINQ? Is giving me the error
"cannot be applied to operands of type double and string"
key = Request.QueryString["key"];
var query = from p in db.VERSIONs where p.vr_key == key select p;
try this:
Double key = Convert.ToDouble(Request.QueryString["key"]);
var query = from p in db.VERSIONs where p.vr_key == key select p;
Use TryParse method to make sure your string is compatible/ convertible because query string can be anything. Otherwise a user can easily break your code simply typing something for key.
double key;
if(Double.TryParse(Request.QueryString["key"], out key))
{
var query = from p in db.VERSIONs
where p.vr_key == key
select p;
}
QueryString without checking is risky.Use SqlFunctions.StringConvert to convert p.vr_key.
Try this:
key = Request.QueryString["key"];
var query = from p in db.VERSIONs where SqlFunctions.StringConvert(p.vr_key) == key select p;
p.vr_keyis of type double like your message says.