use*_*767 13 c# sql-server asp.net-mvc entity-framework asp.net-mvc-3
我在运行应用程序时遇到上述异常.该应用程序使用的是asp.net mvc 3/C#.我制作了一个mdf文件并将其添加到Visual Web Developer Express中的App_Data文件夹下.我在web.config文件夹中添加了连接字符串,但是当我运行并浏览到/ store时,我得到上面的错误并var categories = storeDB.Categories.ToList();
突出显示该行.我的数据库包含6个表,其中一个是Category.
控制器:
EventCalendarEntities storeDB = new EventCalendarEntities();
public ActionResult Index()
{
var categories = storeDB.Category.ToList();
return View(categories);
}
Run Code Online (Sandbox Code Playgroud)
web.config文件中的连接字符串:
<connectionStrings>
<add name="EventCalendarEntities"
connectionString="data source=.\SQLEXPRESS;
Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|\MvcEventCalendar.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
Mar*_*ell 25
这通常意味着一个简单的配置问题:
dbo
计划(它可能在Fred.Categories
)dbo.CATEGORIES
其中任何一个都会导致上述异常.特别是,您声明:
我的数据库包含6个表,其中一个是Category.
现在到机器,Category
!=Categories
小智 6
尝试使用模型构建器类.它是配置或显式定义表和模型类之间的映射的方法.
在您的实体/上下文类中尝试添加此代码
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Category>().ToTable("Category");
}
Run Code Online (Sandbox Code Playgroud)
它是一种方法.确保使用所有包含语句.
归档时间: |
|
查看次数: |
54220 次 |
最近记录: |