SqlException:从核心2.0迁移到2.1的项目上无效的列名'c'

时间:2018-10-29 08:44:06

标签: c# asp.net-core-mvc asp.net-core-2.0 asp.net-core-2.1

我将项目从.net core 2.0迁移到.net core 2.1,并根据文档更改了库。我的整个项目工作正常,但只有我的问题模块在给 this error

我的控制器查询在调试时工作正常,我认为paginatedList中存在问题,但我不知道如何解决。

这是我正在执行的控制器功能。

 public async Task<IActionResult> Index(string sortOrder, string currentFilter, string searchString, int? page)
    {
        ViewData["CurrentSort"] = sortOrder;
        ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
        ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date";
        ViewData["CurrentFilter"] = searchString;

        //Check User Profile is complete or not 
        var user = await _userManager.GetCurrentUser(HttpContext);
        var userPersonalRow = _context.UserPersonalDetail.Where(a => a.UserId == user.Id).SingleOrDefault();
        if (userPersonalRow == null)
        {
            return RedirectToAction("CompleteProfile", "Home");
        }
        var questionList = (from question in _context.UserQuestion
                            join personalInfo in _context.UserPersonalDetail on question.UserId equals personalInfo.UserId
                            select new NewQuestionVM
                            {
                                UserQuestionId = question.UserQuestionId,
                                Description = question.Description,
                                Title = question.Title,
                                Tags = question.Tag.Select(t => new QuestionTagViewModel
                                {
                                    SkillName = t.SkillTag.SkillName,
                                    SkillTagId = t.SkillTagId,
                                }).ToList(),
                                Voting = _context.UserQAVoting.Sum(x => x.Value),
                                Visitors = _context.QuestionVisitor.Where(av => av.QuestionId == question.UserQuestionId).Count(),
                                PostedBy = personalInfo.FirstName + " " + personalInfo.LastName,
                                UserPic = personalInfo.ProfileImage,
                                PostTime = question.PostTime,
                                HasVerifiedAns = question.HasVerifiedAns,
                            }).Take(10);
        if (!String.IsNullOrEmpty(searchString))
        {
            questionList = questionList.Where(s => s.Description.Contains(searchString)
                            || s.Title.Contains(searchString));

        }
        @ViewBag.UName = HttpContext.Session.GetString("Name");
        int pageSize = 10;
        return View(new QuestionListVM { Questions = await PaginatedList<NewQuestionVM>.CreateAsync(questionList.AsQueryable(), page ?? 1, pageSize) });

    }

这是PaginatedList类。

    public class PaginatedList<T> : List<T>
{
    public int PageIndex { get; private set; }
    public int TotalPages { get; private set; }

    public PaginatedList(List<T> items, int count, int pageIndex, int pageSize)
    {
        PageIndex = pageIndex;
        TotalPages = (int)Math.Ceiling(count / (double)pageSize);

        this.AddRange(items);
    }

    public bool HasPreviousPage
    {
        get
        {
            return (PageIndex > 1);
        }
    }

    public bool HasNextPage
    {
        get
        {
            return (PageIndex < TotalPages);
        }
    }

    public static async Task<PaginatedList<T>> CreateAsync(IQueryable<T> source, int pageIndex, int pageSize)
    {
        var count = await source.CountAsync();
        var items = await source.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();
        return new PaginatedList<T>(items, count, pageIndex, pageSize);
    }

    internal static Task<string> CreateAsync<TEntity>(IQueryable<TEntity> queryable, int v, int pageSize) where TEntity : class
    {
        throw new NotImplementedException();
    }
}}

但是我不明白这是怎么给这样的错误的。我很想得到一些帮助。

0 个答案:

没有答案