I need subtract the result of contentCategories from allCategories at the moment I use .Except method but I receive an error.
Any idea what I'm doing wrong... many thanks
Error 2 Argument 1: cannot convert from 'System.Linq.IQueryable<System.Data.Objects.DataClasses.EntityCollection<WebProject.DataAccess.DatabaseModels.CmsCategory>>' to 'System.Data.Objects.ObjectQuery<WebProject.DataAccess.DatabaseModels.CmsCategory>'
int contentId = Int32.Parse(uxContentsListSelector.SelectedValue);
var allCategories = from category in context.CmsCategories select category;
var contentCategories = from content in context.CmsContents
where content.ContentId == contentId
select content.CmsCategories;
var result = context.CmsCategories.Except(contentCategories);
You need to add an additional from in clause in order to get a flattened list.
var contentCategories = from content in context.CmsContents
from cat in content.CmsCategories
where content.ContentId == contentId
select cat;
I would then change your Except method to an Any method
var result = context.CmsCategories.Where(cat => !contentCategories.Any(c => c.CategoryId == cat.CategoryId));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With