Answer the question
In order to leave comments, you need to log in
How to find out the ordinal number of a row in a column (Entity Framework C#)?
Good day.
The code below demonstrates changing the first record in the table. The question is how to change any row in a column by the specified number of this period (and how to find out the row number in general)?
using (var bd = new WS2016Entities())
{
var data = bd.User.FirstOrDefault();
data.Password = Console.ReadLine();
bd.SaveChanges();
}
Answer the question
In order to leave comments, you need to log in
The rows in the database can be in any order that is unpredictable for you. And which line is in which place, you should not be interested. The fact that you see the rows in some sort of order is sorting by default. If you want to take the serial number of the line, then you need to specify the serial number relative to some field, i.e. the table must first be sorted by the desired field (Id, DateTime, Name, etc.), and then you can take a record counting from either end. Therefore, it will approximately look like this.
If you need to find out the serial number of a certain record, then you can do this
bd.User.OrderBy(x => x.Id).ToList().FindIndex(x => x.Name == "Vasya");
Use AI (Auto-increment) on a column named ID, well, this is just an example.
Take other data - please take the FirstOrDefault overload into which you pass the Predicate.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question