我有一个名为 OnlineShoppingContext 的 DBContext 驱动类,如下所示:
public class OnlineShoppingContext:DbContext
{
public OnlineShoppingContext(string connectionString):base(connectionString)
{
}
public DbSet<User> Users { get; set; }
}
我在以下代码中使用它:
using (var context = new OnlineShoppingContext("ConnectionStringValue"))
{
if (context.Users.Any(item => item.Email == Email && item.Password == "pass"))
session["Username"] = Email;
}
但我收到以下异常:
The model backing the 'OnlineShoppingContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
我使用 Delete 重新创建数据库,然后使用 dbcontext 的 CreateIfDoesNotExist 方法,但我再次收到提到的异常。我必须做什么?