0


I used this code in order to Read & Update a value in database which indicate Pageviews of a website.

void Session_Start(object sender, EventArgs e)
{
    intPageView++;
    Session.Add("Online", intPageView);
    DataLayer.MainFunction.UpdateOnlineUser();
}

    public static void UpdateOnlineUser()
    {
        try
        {
            int intCount = 0;
            TaffyPetEntities db = new TaffyPetEntities();
            T_Setting t_s = db.T_Setting.SingleOrDefault(i => i.ID == 1);
            intCount = Convert.ToInt32(t_s.Page_counter);
            intCount++;
            t_s = new T_Setting();
            t_s = db.T_Setting.First(i => i.ID == 1);
            t_s.Page_counter = intCount;
            db.SaveChanges();
        }
        catch (Exception err)
        {
            DataLayer.Error.RegisterError("MainFunction.cs", err.Message);
        }
    }

in local system every thing was good also running speed was good, but when website published and uploaded on the server every thing is changed. The problem is, at the first we haven't any data outout and when you clicked on each link on the website it takes too long to show another page.
to find out problem, i used Performance Analysis of VIsual Studio. at the result page of this analysis i found that this part of above code use 70% of total process:
T_Setting t_s = db.T_Setting.SingleOrDefault(i => i.ID == 1);
The questions is:
1. Is it correct syntax for fetching data in Entity FrameWork at the Data Layer (DAL) of a website?
2. Can i change this code with another method in order to reduce process speed?

Thanks.

4

0 回答 0