我想在我的MVC 4應用程序在VS2012中添加控制器這一形象:添加控制器錯誤無法檢索元數據
型號:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MvcDemo.Models
{
public class MovieDB
{
public int ID { get; set; }
public string Title { get; set; }
public string Director { get; set; }
public DateTime Date { get; set; }
}
public class MovieDBContext : DbContext
{
public DbSet<MovieDB> Movies { get; set; }
}
}
連接字符串:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcDemo-20130315191956;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcDemo-20130315191956.mdf"
providerName="System.Data.SqlClient" />
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|\Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
點擊「添加」後,發生此錯誤:
unable to retrieve metadata for 'MvcDDemo.Models.MovieDB'.Using the
same DbCompiledModel to create contexts against different type of
database servers is not supported.instead,create a
separate DbCompiledModel for each type of server being used.
有什麼建議嗎?
明顯的部分是你的情況下失敗。不明顯的部分是**爲什麼**。這通常是以降序排列,1)web.config中的連接字符串,2)你的db 3),因爲你似乎在使用Code First,你的初始化方法或遷移策略可能是問題。請解釋你已經做了什麼來初始化數據庫,什麼樣的數據庫,什麼有關... – 2013-03-16 05:10:48
好吧,分享你的連接字符串 – 2013-03-16 06:19:44
這絕對是連接到數據庫的問題,但我沒有看到它。你使用的是緊湊型,你的連接看起來很穩固。你正在使用正確的上下文... – 2013-03-16 07:03:09