I have Items and Lines that are linked with the ItemsLines table.
On a web page, I show an item. I want to display in a DropDownList all Lines that are not linked to this Item.
This doesn’t work :
int ItemId = Convert.ToInt32(Request.QueryString["id"]);
ddlLines.DataSource = context.Lines.Where(t => !t.ItemLines.Any(x => x.ItemId == ItemId));
I was trying to get the Lines where(they are not associated to the Item).
I can’t figure out how to do this.
Thank you very much!
EDIT :
This is the error message I get:
the objectcontext instance has been disposed and can no longer be used
Your error is not because your lambda expression is incorrect. Your issue is that the context object you are using to connect to your database has already been disposed of before you call:
The solution is to add a .ToList() to the end of your expression. This is because the .Where lambda expression returns something from the IQueryable interface and everything from that interface still has a connection to the database. So by adding .ToList() it will remove the connection to the database.