尝试设计生成DB的简单代码:
namespace CodeFirstDemo
{
public class Post
{
public int Id { get; set; }
public DateTime DatePublished { get; set; }
public string Title { get; set; }
public string Body { get; set; }
}
public class BlogDbContext : DbContext
{
public DbSet<Post> Posts { get; set; }
}
class Program
{
static void Main(string[] args)
{
}
}
}
的app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name ="BlogDbContext" connectionString ="data source=.\SQLEXPRESS; initial catalog=CodeFirstDemo; integrated security==SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
我执行enable-migrations
后出错:
Format of the initialization string does not conform to specification starting at index 57.
我想我的连接字符串有问题:
<add name ="BlogDbContext" connectionString ="data source=.\SQLEXPRESS; initial catalog=CodeFirstDemo; integrated security==SSPI" providerName="System.Data.SqlClient" />
但到底出了什么问题?
答案 0 :(得分:1)
“综合安全”之后有一个额外的等号。