奇怪的缓存问题与ASP.net/Linq [英] Weird caching issue with ASP.net/Linq

查看:62
本文介绍了奇怪的缓存问题与ASP.net/Linq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写涉及存储配置文件的应用程序。我使用LINQ来访问数据库,但保存配置文件时,有一个奇怪的问题。当我保存它,将它写入到数据库正确的 - 但是当我离开的页面和回来,旧值仍停留在个人资料表格

I'm writing an application involving storing a profile. I'm using Linq to access the database, but having a weird issue when saving a profile. When I save it, it writes to the DB correctly - but when I leave the page and come back, the old values still remain in profile form.

我的个人资料页:

if(!Page.IsPostBack) {
    Profile p = Student.GetProfile(Int32.Parse(Session["userID"].ToString()));
    if (p != null)
    {
          FirstNameTextBox.Text = p.FirstName;
          LastNameTextBox.Text = p.LastName;
          Address1TextBox.Text = p.Address1;
          .....
    }

和我的学生类:

    public static Profile GetProfile(int uID)
    {
        var profile = (from p in db.Profiles
                       where p.uID == uID
                       select p).FirstOrDefault();
        return profile;
    }

我没有做任何花哨的缓存在任何地方,所以不知道旧的值存储在哪里?

I'm not doing any fancy caching anywhere, so not sure where the old values are stored...

**编辑**

因此​​,似乎它是向下到全局LinqDataContext。在我的学生上课,我有:

So, it seems that it's down to a global LinqDataContext. In my Student class, I had:

public class Student
{
    private static LinqClassesDataContext db = new LinqClassesDataContext() { CommandTimeout = 36000 };

    public static Profile GetProfile(int uID)
    {
            var profile = (from p in db.Profiles
                           where p.uID == uID
                           select p).FirstOrDefault();
            return profile;   
    }

如果我给GetProfile方法,它自己的DataContext,问题就解决了​​。

If I give the GetProfile method it's own DataContext, problem solved.

仍然很新的LINQ中,什么对有使用到数据库同样获得众多方法的类的最佳方式?有了这样的全球背景下?或者使用它自己的数据上下文每种方法?

Still being very new to Linq, what's the best way to have a class with numerous methods that use the same access to a database? Having a global context like this? Or each method using it's own data context?

推荐答案

它结束了被我用在DataContext。我不知道是什么原因这个固定的问题,但我改变了我的类从:

It ended up being the DataContext I was using. I'm not exactly sure why this fixed the issue, but I changed my class from:

public class Student
{
   private static LinqClassesDataContext db = new LinqClassesDataContext() { CommandTimeout = 36000 };

   public static Profile GetProfile(int uID)
   {
        var profile = (from p in db.Profiles
                       where p.uID == uID
                       select p).FirstOrDefault();
        return profile;   
   }
}

public class Student
{
   public static Profile GetProfile(int uID)
   {     
        LinqClassesDataContext db = new LinqClassesDataContext();
        var profile = (from p in db.Profiles
                       where p.uID == uID
                       select p).FirstOrDefault();
        return profile;   
   }
}

这篇关于奇怪的缓存问题与ASP.net/Linq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆