Đây là im mã sử dụng để cấu hình cơ sở dữ liệu:Tại sao tôi phải Disable Lazy tải, Entity Framework 4.1 sử dụng Mã Migrations Cấu hình
internal sealed class Configuration : DbMigrationsConfiguration<DataStore>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
SetSqlGenerator("System.Data.SqlServerCe.4.0", new SqlCeModelColumnBugWorkaroundProvider());
}
protected override void OnSeed(DbContext context)
{
context.Configuration.LazyLoadingEnabled = false;
new SeedData(context as DataStore);
}
public static void DoDatabaseInitialisation()
{
var setting = ConfigurationManager.AppSettings["RequiresDbUpdate"];
var requiresDbUpdate = bool.Parse(string.IsNullOrEmpty(setting) ? "false" : setting);
if (! requiresDbUpdate) return;
//otherwise create/update the database
var dbMigrator = new DbMigrator(new Configuration());
dbMigrator.Update();
ResetDbUpdateRequired("/");
}
private static void ResetDbUpdateRequired(string appPath)
{
var hostName = WebHelper.GetHost(false);
if (!hostName.Contains("localhost"))
WebHelper.UpdateWebConfigAppSetting("RequiresDbUpdate", "false", appPath);
}
Nếu ai biết làm thế nào để làm điều này, xin vui lòng cho tôi biết. Tôi cũng đã thử các thuộc tính phi ảo trên các lớp mô hình nhưng điều này dường như không tạo ra sự khác biệt nào cả.
Vâng tôi đã thử phương pháp này rồi, nó hoạt động chính xác mà không cần mã di chuyển đầu tiên. Vì vậy, tôi nghĩ rằng đó là một cái gì đó để làm với điều đó tại sao nó không hoạt động ... – woz