Some basics
I have two tables, one of which contains users, and the other a log with logins. The user table contains approximately 15,000 users, the login table grows and reaches 150,000+ messages. The database is built on SQL Server (not express).
To manage users, I got a gridview (ASPxGridView from Devexpress), which I populate from ObjectDatasource.
Are there any common dos and donts that I should know about when summing up the number of logins made by the user.
Things are becoming strangely slow.
Here is an image showing the tables involved. 
Ive tried a few things.
DbDataContext db = new DbDataContext(); // Using foregin key relationship foreach (var proUser in db.tblPROUsers) { var count = proUser.tblPROUserLogins.Count; //... }
Lead Time: 01: 29.316 (1 minute and 29 seconds)
Lead time: 01: 18.410 (1 minute and 18 seconds)
Lead time: 01: 15,821 (1 minute and 15 seconds)
The best performance model is actually a dictionary. However, I know of any options that I would like to hear about this, also if there is something βbadβ with this type of encoding when processing such large amounts of data.
thanks
==================================================== ======
UPDATED With model according to BrokenGlass example
Lead time: 02: 01.135 (2 minutes and 1 second)
In addition to this, I created a list in which a simple class was stored
public class LoginCount { public int UserId { get; set; } public int Count { get; set; } }
And in the summation method
var loginCount = new List<LoginCount>(); // This foreach loop takes approx 30 secs foreach (var login in db.tblPROUserLogins) { var userId = login.UserId; // Check if available var existing = loginCount.Where(x => x.UserId.Equals(userId)).FirstOrDefault(); if (existing != null) existing.Count++; else loginCount.Add(new LoginCount{UserId = userId, Count = 1}); } // Calling it foreach (var proUser in tblProUser) { var user = proUser; var userId = user.UserId; // Count logins var count = 0; var loginCounter = loginCount.Where(x => x.UserId.Equals(userId)).FirstOrDefault(); if(loginCounter != null) count = loginCounter.Count; //... }
Lead Time: 00: 36.841 (36 seconds)
Conclusion so far, summing with linq is slow, but Im getting there!