Except
is a set subtraction operator - you use it by supplying elements of the same kind as the original set to request the removal of all elements of the Except
set from the original set.
This is not what you are trying to achieve here - your task appears to be a simple filtering:
ticket = db.Tickets
.Include(o => o.Ticket)
.Where(o => o.AttachmentFile == null && o.TicketID == ticketID)
.ToList();
This excludes all tickets with attachments by requiring the AttachmentFile
to be null
.
(Comment) I just want to ignore the o.attachmentFile I don't want to get it if it's null.
That's different: EF does not support lazy loading of individual properties, so unless the attachment is split in its own table (which I would recommend doing if you often query tickets without their attachments) you should select only the fields that you want to get:
ticket = db.Tickets
.Include(o => o.Ticket)
.Where(o => o.TicketID == ticketID)
.Select(o => new MyObject(o.Attr1, o.Attr2, /*and so on, but no AttachmentFile */))
.ToList();