I’m trying to select a row in my database by its ID and then select all rows that have a “Position” value higher than the row selected by ID, like this:
int id = Convert.ToInt32(Request.QueryString["id"]);
MyDataContext d = new MyDataContext
Item itemID = d.Items.Single(row => row.ID == id);
Item itemPos = d.Items.Select(row => row.Position > itemID.Position);
The bottom line is saying that an explicit conversion exists but I can’t seem to fix it
Having read the answers so far, the code now looks like this:
int id = Convert.ToInt32(Request.QueryString["id"]);
MyDataContext d = new MyDataContext
Item itemID = d.Items.Single(row => row.ID == id);
var itemPos = d.Items.Where(row => row.Position > itemID.Position);
But then when I try and edit the Position of selected rows, it seems I am doing that wrong:
itemPos.Position = itemPos.Position - 1;
I would have expected that line to reduce the current position by 1.
I’m still new to all this
Your select statement will return you an
IEnumerable<Item>, whereas the type you are specifying is for a singleItem. you may try the following.Use var for implicit type, or use
IEnumerable<Item>for explicit type, since you are selecting on the basis of a condition you may useWhereclause instead ofSelect