EF连接字符串小问题记录
1.EFDbContext”不包含必需的 providerName 特性:
<connectionStrings> <add name="EFDbContext" providerName="System.Data.SqlClient" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=SportsStore;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"/> </connectionStrings>
2.当的数据上下文类的名称为连接字符串中,设置的name的名字相同时,不必特意指定连接字符串。但是,如果字符串名称(name)和数据上下文类的名称不同时,需要指定字符串的名字
eg:
<connectionStrings> <add name="EFDbContext" .../> </connectionStrings> public class EFDbContext : DbContext { public DbSet<Product> Products { get; set; } }
<connectionStrings> <add name="EFDbConnStr" .../> </connectionStrings> public class EFDbContext : DbContext { public EFDbContext() : base("EFDbConnectStr") { } public DbSet<Product> Products { get; set; } }