实体框架返回具有可处理上下文的旧数据 [英] Entity Framework returning old data with disposable context

查看:38
本文介绍了实体框架返回具有可处理上下文的旧数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次遇到此问题.

This is the first time I'm seeing this problem.

考虑我的存储库方法:

public async Task<List<Code>> GetAllByType(string type)
{
    using (var ctx = new DatabaseContext())
    {
        return await ctx.Codes.Where(code => code.Type.Equals(type)).ToListAsync();
    }
}

这是我尝试为我的视图创建可观察的集合时偶然发现的问题,该视图是根据上述方法的结果创建的.因此:

This is the issue I've stumbled upon while trying to create an observable collection for my view that is created from the result of the method above. As so :

Types = new ObservableCollection<Code>(await CodeRepository.GetAllByType("TestType"));

即使我使用的是一次性上下文,每次执行查询时,存储库都会返回旧数据.我已经使用"TestType"作为列值手动编辑了某些条目,它仍然是未更改的旧数据.我添加了3个新条目,它们是 找不到 .

Even though I'm using a disposable context, every time I make a query, the repository returns old data. I've manually edited some of the entries with "TestType" as their column value, it's still the unchanged old data. I've added 3 new entries, those are not found.

是的,我在数据库中确实有条目.数据库不区分大小写,无论如何我都尝试了所有组合-Entity Framework上下文仍在返回旧数据.

Yes, I do have entries in the database. Database is non-case-sensitive, I've tried all combinations, whatever I do - Entity Framework context is still returning old data.

以前有人遇到过这个问题吗?

Anyone had this issue before?

提前谢谢!

推荐答案

您可能正在编辑错误的数据库.请仔细检查您的连接字符串,并确保您正在编辑应用程序实际连接到的字符串.

You are probably editing the wrong database. Please double-check your connection string and make sure that you are editing the one that your application actually connects to.

这篇关于实体框架返回具有可处理上下文的旧数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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