There are two classes: server and match.

public class Server { public int Id {get; set;} ... public virtual ICollection<Match> Matches {get; set;} } public class Match { public int Id {get; set;} public sting Timestamp {get; set;} ... public virtual Server Server {get; set;} } 

One-to-many connection between them. You need to calculate the average number of matches per day on each server.

Now I do it like this (I tried it differently): in the class, the server defined the method

 public double GetAverageMatchesByDay() { if (Matches.Count == 0) return 0; retrun Matches .ToList() .GroupBy(m => DateTimeOffset.Parse(m.Timestamp).UtcDateTime.Date) .Select(g => g.Count()) .Average(); } 

Well, then, where necessary:

 foreach(var server in context.Servers) { var averageMatchesPerDay = server.GetAverageMatchesPerDay(); } 

The problem is that with 10,000 servers and only 10 matches for each, it has been working for a very long time, there are a lot more matches.

How to properly reorganize the connection, or the method of storage, or the method of sampling all this, so that the response rate does not exceed a couple of seconds?

Thank you in advance.

  • You keep the timestamp string? Do you realize that it is precisely because of the string type that you cannot calculate the desired value on the server? .. - Pavel Mayorov
  • @PavelMayorov With your comment finally realized it, but do not be so rude. Thank. - CRRRRRRRRASH
  • @PavelMayorov only with this approach, when I need a reverse process, i.e. To convert the date from the database to the format I need, the same problem arises. - CRRRRRRRRASH

0