MVC使用实体框架创建具有读/写操作和视图的控制器。错误
问题描述:
所以,我想学习如何使用MVC框架。 我用这个链接的教程来接这个框架了: https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-aspnet-mvc3/cs/adding-a-viewMVC使用实体框架创建具有读/写操作和视图的控制器。错误
我有问题创造了我的模型,命名的影片控制器,我遇到这时候我已经达到一步“访问你的模型我解决不了的错误从控制器的数据(C#)”
每次我尝试创建一个控制器等的指令,告诉我,我收到此错误: enter image description here
我还在这里新手,所以我不;吨真的知道什么做, 我试图改变Web中的providerName。配置到同一作为第二的ConnectionStrings但同样的错误继续出现,我的模型代码看起来一模一样,因为我提供的
Movie.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace WebApplication1.Models
{
[Table("Movies")]
public class Movie
{
[Key]
public int movieid { get; set; }
public string movie_title { get; set; }
public DateTime release_date { get; set; }
public string Genre { get; set; }
public decimal ticket_price { get; set; }
}
public class MovieDBContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
}
}
我的web.config部分中的链接
<connectionStrings>
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlClient"/>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20170909114325.mdf;Initial Catalog=aspnet-WebApplication1-20170909114325;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
请包括您的电影课程代码。 –
完成,Movie.cs添加 –
如果链接的答案对您没有帮助,请将movie_id更改为MovieId或Id或将[Key]直接添加到movie_id上方。 –