我是否需要同时处置 CRM OrganizationServiceProxy 和 OrganizationServiceContext?
OrganizationServiceProxy 和 OrganizationServiceContext 都支持 dispose 方法。我需要将它们都包装在 using 语句中吗?
using (var proxy = GetOrganizationServiceProxy(Constants.OrgName))
{
using (var context = new OrganizationServiceContext(proxy))
{
// Linq Code Here
}
}
或者处理上下文关闭是否会正确关闭代理,这意味着只需要这个?
var proxy = GetOrganizationServiceProxy(Constants.OrgName)
using (var context = new OrganizationServiceContext(proxy))
{
// Linq Code Here
}
Both the OrganizationServiceProxy and the OrganizationServiceContext support the dispose method. Do I need to wrap both of them in a using statement?
using (var proxy = GetOrganizationServiceProxy(Constants.OrgName))
{
using (var context = new OrganizationServiceContext(proxy))
{
// Linq Code Here
}
}
Or will disposing of the context close properly close the proxy, meaning only this is needed?
var proxy = GetOrganizationServiceProxy(Constants.OrgName)
using (var context = new OrganizationServiceContext(proxy))
{
// Linq Code Here
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上下文无法处置代理,因为它无法决定它是否被任何其他对象使用。
如果您查看 OrganizationServiceContext 的
Dispose
,您会看到顺便说一句。您可以将两个 using 语句结合起来
The context cannot dispose the proxy, as it cannot decide if it is used by any other object.
IF you look into
Dispose
of OrganizationServiceContext, you'll seebtw. you can combine both using statements