简体   繁体   中英

Linq to SQL fetching cached results

when I select objects using Linq, i seem to get cached results at first.

I use the following code to fetch an applicant from the DB on GET requests assume that this data is STATE_1

using (AdmissionsAppEntities db = new AdmissionsAppEntities())
{
    // Fetch the user
    ApplicationData applicant = (from a in db.ApplicationDatas
                                         where a.userGUID == userGUID
                                         select a).SingleOrDefault();
}

and the following code to save changes against this record on POST requests, after the SaveChanges is called this record should be in STATE_2

using (AdmissionsAppEntities db = new AdmissionsAppEntities())
{
    // Fetch the user
    var applicant = (from a in db.ApplicationDatas
                       where a.userGUID == userGUID
                       select a).SingleOrDefault();

    if (applicant != null)
    {
        // Save page 1 data
        ...
        applicant.lastUpdate = DateTime.Now;

        db.Entry(applicant).State = EntityState.Modified;
        DataBag.result = db.Entry(applicant).GetValidationResult();
        if (DataBag.result.ValidationErrors.Count == 0)
        {
            db.SaveChanges();
        }
    }
}

if (DataBag.result.ValidationErrors.Count == 0)
{
    return RedirectToAction("PageTwo");
}

The database properly saves STATE_2 (i can see it in the db if I use a sql inspection tool), but on subsequent pageload, STATE_1 is retrieved.

I see tons of results where people are having this issue, but no ideas on how to fix it.

UPDATE 1

I moved the RedirectToAction calls (all my returns) to outside the using block to make sure that each DbContext's Destroy function gets called. Did not appear to solve the problem.

人们实际上遇到了这个问题,所以我将不再赘述,最终我的问题是Orchard CMS将模块页面缓存。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM