Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取缓存实体的对象上下文_C#_Entity Framework_Caching_Objectcontext - Fatal编程技术网

C# 获取缓存实体的对象上下文

C# 获取缓存实体的对象上下文,c#,entity-framework,caching,objectcontext,C#,Entity Framework,Caching,Objectcontext,我想手动创建实体关系,对象取自缓存 Car car = Cache.GetCarById(1); // takes this from cache SteeringWheel steeringWheel = Cache.GetSteeringWheelById(1); //takes this from DB //also saves in cache car.Steeri

我想手动创建实体关系,对象取自缓存

Car car = Cache.GetCarById(1); // takes this from cache
SteeringWheel steeringWheel = Cache.GetSteeringWheelById(1); //takes this from DB 
                                                             //also saves in cache
car.SteeringWheel = steeringWheel; 
关于上述任务

无法定义两个对象之间的关系,因为 它们附着到不同的ObjectContext对象

我尝试了以下方法:

将steeringWheel保存在缓存中后从缓存中返回,从而生成2 对同一实体的缓存请求 将每个实体从它的 在缓存之前拥有自己的上下文 以上都不起作用。如果我能得到汽车的上下文,我会把方向盘连接到它上,但是。。。什么背景?上下文是否与缓存中的对象一起保存?如何获取它

请注意,我并不真正需要上下文,我只是按原样显示这些数据

乐: 上下文是跨一个http请求的共享上下文,从静态方法使用

public static myEntities Context
    {
        get
        {
            string ocKey = "ocm_" + HttpContext.Current.GetHashCode().ToString("x");
            if (!HttpContext.Current.Items.Contains(ocKey))
                HttpContext.Current.Items.Add(ocKey, new myEntities());
            return HttpContext.Current.Items[ocKey] as myEntities;
        }
    }

你能展示一下上下文是如何定义的吗?看起来你需要展示更多的代码,我们在这里不是读心术的人SO@DJKRAZE我添加了关于它的信息,希望它有助于在缓存工作之前从上下文中分离,有一个位置我没有这样做。