在调试模式下的ObjectContext公开,内部在释放模式 [英] ObjectContext public in debug mode, internal in release mode

查看:148
本文介绍了在调试模式下的ObjectContext公开,内部在释放模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的方法,使一个ObjectContext的公众在调试模式和内部在释放模式?

Is there an easy way to make an ObjectContext public in debug mode and internal in release mode?

使用Linqpad它是连接到一个ObjectContext的快速测试和查询非常方便,因此对于开发目的,我希望它是公共的。但我不希望想到后果时一样方便的部署到一些聪明的客户。

With Linqpad it is very convenient to connect to an ObjectContext for quick testing and querying, so for development purposes I want it to be public. But I don't want to think of the consequences when the same convenience is deployed to some smart customer.

推荐答案

正如评论,这可能不是什么实际用途,但:

As mentioned in the comment, this may not be of any practical use, but:

#if DEBUG
public
#endif
class YourContext : ObjectContext
{
    ...
}

在与所生成的的ObjectContext 从.edmx文件时,您将需要自定义如何生成的C#文件。默认值是不能自定义,但设计师有一个选项添加code代项目。如果你使用它,你会得到几个选项。我使用ADO.NET自跟踪实体发生器,但同样的方法适用于所有的人。选择此增加了两个模板文件(Model.tt和Model.Context.tt)到你的项目,你是自由的,你认为合适的修改。对于你问的修改,你会发现<#= Accessibility.ForType(容器)#>部分类 Model.Context.tt 文件。您可以更新这一点,以便它读取

When dealing with a generated ObjectContext from a .edmx file, you'll need to customize how C# files are generated. The default is not customizable, but the designer has an option "Add Code Generation Item". If you use this, you'll get several options. I'm using "ADO.NET Self-Tracking Entity Generator", but the same way works for all of them. Choosing this adds two template files (Model.tt and Model.Context.tt) to your project, which you are free to modify as you see fit. For the modification you're asking about, you'll find <#=Accessibility.ForType(container)#> partial class in the Model.Context.tt file. You can update this so that it reads

#if DEBUG
<#=Accessibility.ForType(container)#>
#endif
partial class

这篇关于在调试模式下的ObjectContext公开,内部在释放模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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