我的代码存在问题。我有这个类在文件KekantoContext.cs我在web.config中需要两个连接字符串吗?
public class KekantoContext : DbContext
{
public DbSet<Lugar> Lugares { get; set; }
public DbSet<Categoria> Categorias { get; set; }
public DbSet<UserMessage> UserMessages { get; set; }
}
而且我在AccountModel.cs文件中的另一个类:
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
我想知道,如果有必要在2个连接字符串我web.config文件。
我有这样的:
<connectionStrings>
<add name="KekantoContext"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Kekanto.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
<add name="UsersContext"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Kekanto.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
的代码没有与这些2周的ConnectionStrings工作,但我想知道,如果可能的解决方案需要2个连接字符串
在运行时... 现在我habing问题,它说:“因为数据库是模型支持的‘UsersContext’语境已经改变考虑使用Code First Migrations来更新数据库“即使我进行了迁移,它仍然不起作用 –
检查代码中的UserProfile对象是否与连接字符串指向的数据库中的字段匹配。这些需要完美匹配,否则它不能映射数据库和本地对象。 – nik0lias