Commit f0633a9f authored by Kirill's avatar Kirill

Добавление Files в базу данных без коллизий. Создание базы данных в persistent директории

parent 13c40374
......@@ -44,8 +44,9 @@ namespace TourDataManager {
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
// Ещё, вероятно, помогло бы [DatabaseGenerated(DatabaseGeneratedOption.None)]
var sqliteConnectionInitializer = new SqliteDropCreateDatabaseWhenModelChanges<MyDbContext>(modelBuilder);
var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<MyDbContext>(modelBuilder);
Database.SetInitializer(sqliteConnectionInitializer);
}
public DbSet<Estate> Estates{ get; set; }
......@@ -62,7 +63,7 @@ namespace TourDataManager {
private MyDbContext context;
public Db(){
connection = new SQLiteConnection("data source=mylovelybase.sqlite");
connection = new SQLiteConnection($"data source={TourDataManager.GetPathInPersistent("sandbox.sqlite")}");
context = new MyDbContext(connection,true);
}
......@@ -89,9 +90,8 @@ namespace TourDataManager {
}
public void InsertFiles(IEnumerable<File> files){
foreach (var file in files){
context.Files.AddOrUpdate(file);
}
var diff = files.Where(file => !context.Files.Any(file1 => file.Url == file1.Url));
context.Files.AddRange(diff);
context.SaveChanges();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment