I think the main problem here is multiple app domains in ASP.NET. Setting u.Views += 1 is nice but with ASP.NET you could have several instances of the application - they would both update Views independently so the value is wrong. The way to solve that would be to store the number of views as a field on the user in the database. Then the issue becomes how do you update it? There isn't in LINQ to SQL a hook for selection e.g. OnUserSelect() as there is for updates/inserts etc. Instead I would suggest a static method on the User class for doing the selection that updates the count and returns the user in one go. The first thing this method does is call a stored procedure, lets say UpdateUserCount(username) which updates the count value of the user you're about to access. Then the routine does the LINQ select and returns the user. for example:
public static User SelectUser(string username)
{
var dx = new MyDataContext();
dx.UpdateUserCount(username);
return dx.Users.Single( u => u.Username == username);
}
'Howard