c# - Cannot implicitly convert type 'System.Linq.IQueryable? -
here code giving me above error
public actionresult edit(int id = 0) { kbs_virtual_trainingentities db = new kbs_virtual_trainingentities(); userscontext ctx = new userscontext(); userprofile model = ctx.userprofiles.find(id); list<coursesubscription> user_course_subscriptions = new list<coursesubscription>(); foreach (usersubscription sub in db.usersubscriptions) { if (sub.id == id) { user_course_subscriptions.add(sub.coursesubscription); } } list<coursesubscription> not_subscribe = db.coursesubscriptions.except(user_course_subscriptions); var courseslist = courses in not_subscribe select new selectlistitem { text = courses.course.name, value = courses.course.id .tostring() }; var coursestype = coursetypes in db.coursetypes.tolist() select new selectlistitem { text = coursetypes.name, value = coursetypes.id .tostring() }; viewbag.courseid = courseslist; viewbag.type = coursestype; return view(model); }
i trying find course subscription not subscribe current user using above code not working?
you're missing tolist
on results except
function. tolist
so:
list<coursesubscription> not_subscribe = db.coursesubscriptions.except(user_course_subscriptions).tolist();
or since in code you're not doing needs list, var
or assign correct type such iqueryable<coursesubscription>
it.
var not_subscribe = db.coursesubscriptions.except(user_course_subscriptions);
Comments
Post a Comment