无法隐式转换类型"System.Linq.IQueryable?



这是我的代码,给我上面的错误

    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 = from courses in not_subscribe
                          select new SelectListItem
                          {
                              Text = courses.Course.Name,
                              Value = courses.Course.ID
                              .ToString()
                          };
        var CoursesTYPE = from CourseTypes in db.CourseTypes.ToList()
                          select new SelectListItem
                          {
                              Text = CourseTypes.Name,
                              Value = CourseTypes.ID
                              .ToString()
                          };
        ViewBag.CourseID = coursesList;
        ViewBag.type = CoursesTYPE;
        return View(model);
    }

我正试图通过使用上述代码找到当前用户不订阅的课程订阅,但它不起作用?

您在Except函数的结果上缺少ToList。像这样做ToList:

List<CourseSubscription> not_subscribe = db.CourseSubscriptions.Except(user_Course_subscriptions).ToList();

或者因为在你的代码中你不做任何需要列表的事情,简单地var它或为它分配正确的类型,如IQueryable<CourseSubscription>

var not_subscribe = db.CourseSubscriptions.Except(user_Course_subscriptions);

相关内容

  • 没有找到相关文章

最新更新