以后可以从对象中提取实体框架的上下文吗? [英] Can context of Entity Framework be extracted from object later on?

查看:40
本文介绍了以后可以从对象中提取实体框架的上下文吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到我使用类似的代码(使用或不使用(考虑使用(??)可能会处理上下文)):

Considering that I use code like (with or without using (considering that using(??) may dispose context)):

IQueryable<Konsultanci> listaKonsultantow;
using (var context = new EntityBazaCRM(Settings.sqlDataConnectionDetailsCRM)) {
       listaKonsultantow = from k in context.Konsultancis
                                                   select k;
}

我能否以某种方式提取稍后从 Konsultanci 对象使用的上下文,以便我不必在类的顶部存储上下文?

Can I somehow extract context that was used from Konsultanci object later on so I don't have to store context on top of the class?

 foreach (Konsultanci test in listaKonsultantow) {
       // get context here? 
 }

推荐答案

因为你在 using 块的末尾处理了你的上下文,所以你甚至不应该尝试.

Since you dispose your context at the end of the using block you should not even try.

这篇关于以后可以从对象中提取实体框架的上下文吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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