Answer the question
In order to leave comments, you need to log in
How to save records sorted in the database?
Hey! Me interests, how it is possible to thrust the sorted list in the table DB?
I debugged the code - into the saveThis variable => records are sorted by field, but after storing in the database - everything is chaotic
var saveThis = request.SomeField.Select(r => new Table2Db
{
...
}).OrderBy(x => x.FieldIntNumber).ToList();
ctx.Table2Db.AddRange(errorDbs);
//manipulation with another Table1
....
ctx.SaveChanges()
Answer the question
In order to leave comments, you need to log in
Most DBMSs do not guarantee the order in which records will appear when querying without sorting.
So if you need some specific order - use ORDER BY.
If you have some kind of complex sorting there, add a serial number when inserting and sort by it.
Furthermore. It is almost forbidden to use the order of rows in the database. That is, by numbering. Access is by key or predicate. If you need to store the sorted list - in the cache.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question