By the call of context.xticketitem.Select(p => p.TicketID == ticketID);
you will get a list of booleans that do not exist in context.
I think you should do something like this:
var ticketitem = context.xticketitem.Where(p => p.TicketID == ticketID);
ticketItem.ToList().ForEach(r => context.xticketitem.DeleteObject(r));
context.SaveChanges();
EDIT:
I've moved .ToList()
on the next line to make differences between our snippets more evident. Let's try revise it step by step:
When you call var ticketitem = context.xticketitem.Select(p => p.TicketID == ticketID);
You are creating query that will go by all xticketitems and return whether each item's TicketID equals ticketID variable passed as an argument to your Delete method.
Result of this query is IEnumerable<bool>
.
My code returns IEnumerable<xticketitem>
. It's main difference.
When you call context.DeleteObject(r)
your r
variable is bool. and you are calling DeleteObject method on context. That mathod accepts parameter of type object
(that's why you don't get error at compile time).
I'm calling DeleteObject on xticketitem
ObjectSet that accepts strogly-typed parameter of xticketitem
type.