【发布时间】:2012-09-04 16:40:35
【问题描述】:
我正在尝试使用 SQL Server 精简版 4.0 创建一个简单的 EF 代码第一个示例。 使用的技术包括:Visual Studio 2012 Ultimate。
所以我创建了一个简单的 poco 类:
namespace MvcApplication2.Models
{
public class Customer
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
}
}
还有一个简单的上下文类:
namespace MvcApplication2.Models
{
public class CustomerEntity : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
}
然后我尝试使用模板创建一个控制器类:MVC Controller with read/write actions and views using entity framework.
- 模型类 -> 客户
- 数据上下文类 -> CustomerEntity
我收到以下错误:
无法检索元数据... 使用相同的 dbcompiledmodel 不针对不同类型的数据库服务器创建上下文 支持的。 ...
我应该说这个完全相同的代码使用 LocalDB 没有问题。
我认为唯一需要的区别是在 web.config 文件中添加了以下内容。
<add name="CustomerEntity"
connectionString="Data Source=|DataDirectory|CustomerEntity.sdf"
providerName="System.Data.SqlServerCe.4.0" />
我还错过了什么吗?
我知道我不可能是唯一遇到此问题的人。
【问题讨论】:
标签: asp.net-mvc entity-framework