I am building a .NET app that gets data from Telegram. I am storing Telegram Channels, Topics and Messages in a SQLite database. The structure of the database looks like this:
Basically:
- Channels can or can not have many Topics
- Channels can have many messages
- Topics can have many messages
I want to be able to properly retrieve Channels, Topics and Messages so when I sync from Telegram I don’t insert duplicates. I have a few test channels where I have 100s of topics and 10000s of messages and as one would expect, a LINQ call like this is awful
var channels = teleContext.Channels
.Include(a => a.Messages)
.Include(a => a.Topics).ToList();
Even if I add a Where
to that query it is slow (for instance where ChannelID == someVariable
). I need to be able to update most columns in Channels, a few in Topics and nearly all in Messages (to ensure data is accurate with Telegram).
Is there a combination of eager loading and split queries that I can implement to make the calls to the DB perform better?