我在使用EFCodeFirst碰到的问题!
继承与DbContext的实体类模型,必须和将要新建的数据库的名字相同,因为我开始明白的时候有些随意性,遇到了如下s问题!
异常信息:
提供程序未返回 ProviderManifestToken 字符串。
在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 – 定位指定的服务器/实例时出错)
public class TestClass
{
public int ID { get; set; }
public string testString { get; set; }
public string testName { get; set; }
}
public class TestClassDB : DbContext
{
public DbSet<TestClass> Test { get; set; }
}
连接字符串要写成如下形式:
<connectionStrings>
<add name="TestClassDB"
connectionString=" data source=LKE-SERVER\LKSQLSERVER;Initial Catalog=TestClassDB;Integrated Security=False;User ID=MusicStore;Password=888888888"
providerName="System.Data.SqlClient" />
</connectionStrings>
数据库名Initial Catalog=TestClassDB 要和public class TestClassDB : DbContext相同!
问题二:
Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.
出现这个问题是我在学习mvc3.0的 音乐商店模型中出现的!我直接将数据库加进了SQLSERVER 出现这个问题 也很好解决,不要加数据库进去,然代码自己生成数据库!