C# 插入大量数据实体框架7(核心),UWP
在实体框架7中,我存储字典中的单词,其结构如下:C# 插入大量数据实体框架7(核心),UWP,c#,entity-framework,sqlite,win-universal-app,entity-framework-core,C#,Entity Framework,Sqlite,Win Universal App,Entity Framework Core,在实体框架7中,我存储字典中的单词,其结构如下: [Table("Dictionaries")] public class Dictionary { public int DictionaryId { get; set; } public string Name { get; set; } public virtual List<Word> Words { get; set; } } [Table("Words")] public class Word {
[Table("Dictionaries")]
public class Dictionary
{
public int DictionaryId { get; set; }
public string Name { get; set; }
public virtual List<Word> Words { get; set; }
}
[Table("Words")]
public class Word
{
public int WordId { get; set; }
public string Text { get; set; }
public int DictionaryId { get; set; }
public Dictionary Dictionary { get; set; }
}
public class DictionaryContext : DbContext
{
public DbSet<Dictionary> Dictionaries { get; set; }
public DbSet<Word> Words { get; set; }
}
var dictionary = new Dictionary {
Name = jsonDictionary.Name,
Words = GetWords()
};
大约有9万字。我想快点把它存起来。
我试过:
db.ChangeTracker.AutoDetectChangesEnabled = false;
db.ChangeTracker.QueryTrackingBehavior = Microsoft.Data.Entity.QueryTrackingBehavior.NoTracking;
db.Dictionaries.Add(dictionary); // Lasts 1874.789 seconds
await db.SaveChangesAsync(); // Lasts 740.840
在一台速度很快的电脑里几乎需要一个小时。我试过几次反复思考,比如将单词存储在100、1000块中,但所有的测试都非常慢
有没有办法在SQLite中快速存储大量的数据?您是否尝试过并行添加它们?谢谢,但这似乎不是并行问题。处理器以100%的速度工作。