Commit f0633a9f authored by Kirill's avatar Kirill

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

parent 13c40374
...@@ -44,8 +44,9 @@ namespace TourDataManager { ...@@ -44,8 +44,9 @@ namespace TourDataManager {
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
// Ещё, вероятно, помогло бы [DatabaseGenerated(DatabaseGeneratedOption.None)] // Ещё, вероятно, помогло бы [DatabaseGenerated(DatabaseGeneratedOption.None)]
var sqliteConnectionInitializer = new SqliteDropCreateDatabaseWhenModelChanges<MyDbContext>(modelBuilder); var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<MyDbContext>(modelBuilder);
Database.SetInitializer(sqliteConnectionInitializer); Database.SetInitializer(sqliteConnectionInitializer);
} }
public DbSet<Estate> Estates{ get; set; } public DbSet<Estate> Estates{ get; set; }
...@@ -62,7 +63,7 @@ namespace TourDataManager { ...@@ -62,7 +63,7 @@ namespace TourDataManager {
private MyDbContext context; private MyDbContext context;
public Db(){ public Db(){
connection = new SQLiteConnection("data source=mylovelybase.sqlite"); connection = new SQLiteConnection($"data source={TourDataManager.GetPathInPersistent("sandbox.sqlite")}");
context = new MyDbContext(connection,true); context = new MyDbContext(connection,true);
} }
...@@ -89,9 +90,8 @@ namespace TourDataManager { ...@@ -89,9 +90,8 @@ namespace TourDataManager {
} }
public void InsertFiles(IEnumerable<File> files){ public void InsertFiles(IEnumerable<File> files){
foreach (var file in files){ var diff = files.Where(file => !context.Files.Any(file1 => file.Url == file1.Url));
context.Files.AddOrUpdate(file); context.Files.AddRange(diff);
}
context.SaveChanges(); 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