C# 为什么说';无效的对象名称-胶片?';

C# 为什么说';无效的对象名称-胶片?';,c#,asp.net-mvc,asp.net-core,.net-core,C#,Asp.net Mvc,Asp.net Core,.net Core,我正在构建的.Net应用程序中有一个FilmController,它可以打印出要在页面上显示的电影列表 这使用自动生成的脚手架控制器FilmsController.cs中的索引函数 using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using

我正在构建的.Net应用程序中有一个FilmController,它可以打印出要在页面上显示的电影列表

这使用自动生成的脚手架控制器FilmsController.cs中的索引函数


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.Rendering;
    using Microsoft.EntityFrameworkCore;
    using MvcFilm.Data;
    using MvcFilm.Models;
    
    namespace MvcFilm.Controllers
    {
        public class FilmsController : Controller
        {
            private readonly MvcFilmContext _context;
    
            public FilmsController(MvcFilmContext context)
            {
                _context = context;
            }
    
            // GET: Films
            public async Task<IActionResult> Index()
            {
                return View(await _context.Film.ToListAsync());
            }

这肯定可以创建对象,不是吗

谢谢


Robert

您的数据库是否已更新?记住运行ef迁移:dotnet ef迁移添加我的东西,然后dotnet ef数据库更新使用
scaffold dbcontext
更新数据库上下文。大多数情况下,该表已被删除或重命名。是否添加了迁移??如果您只是创建了模型和DbContext,那还不够。@alessandro-干杯。我已经运行了迁移,但可能在某个地方出现了错误,所以我删除了它们并再次运行它们,这次链接似乎可以正常工作-谢谢!
namespace MvcFilm.Models
{
    public class Film { 
    
        // id field required by the database for the primary key
        public int Id { get; set; }
        public string Title { get; set; }

        [DataType(DataType.Date)] // specifies the type of data (Date).
        public DateTime ReleaseDate { get; set; }
        // The user not required to enter time information in the date field
        // Only the date is displayed, not time information.
        public string Genre { get; set; }

        [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18,4)")]
        public decimal Price { get; set; }
    }
}