扩展数据集类不起作用
我使用数据集设计器创建了一个数据集。我的一个表名为 Users
,因此有一个名为 UsersDataTable
的类。这个类中有一些属性,即Connection
。因此,我创建了一个 Partial Class UsersDataTable
,但设计器代码隐藏文件中的 UsersDataTable
类中的任何例程、属性或变量对我来说都是不可见的。
我只是想扩展该类以添加我自己的例程,但利用设计器生成的类的连接和强类型。我尝试创建自己的部分类并测试它们,看看其他类是否有问题,但我没有。只有使用这些数据集设计器生成的类,我才能访问部分类的另一半中的项目。
我正在 .Net 4 中工作。我可能做错了什么?
I've created a dataset using the dataset designer. One of my tables is called Users
and so there is a class called UsersDataTable
. In this class are some properties, namely Connection
. So I created a Partial Class UsersDataTable
, but none of the routines, properties, or variables from the UsersDataTable
class in the designer codebehind file are visible to me.
I'm simply trying to extend the class to add my own routines but leverage the connections and strong typing of the designer-generated class. I've tried creating my own partial classes and testing them to see if I have the problem with other classes and I don't. Only with these dataset designer-generated classes can I not access items in the other half of the partial class.
I'm working in .Net 4. What might I be doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有“部分”类都必须如此声明才能使该技术发挥作用,我猜测 Visual Studio 数据集设计器不会生成部分类
: com/en-us/library/wa80x488%28v=VS.100%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/wa80x488(v=VS.100).aspx
您可能需要从设计器生成的类继承。
编辑:刚刚查看了一些 VS2010 生成的 DataSet 类,它们确实是部分的,因此假设您使用的是 .NET 4,您的也应该是部分的。我会进一步调查。
进一步编辑:
好的,由于设计器将 *DataTable 类创建为继承自 DataSet 的类中的嵌套类,因此您可能需要在部分类中执行相同的操作:
这似乎对我有用。
All of the "partial" classes must be declared as such in order for this technique to work, and I'm guessing the Visual Studio DataSet designer isn't generating partial classes:
http://msdn.microsoft.com/en-us/library/wa80x488(v=VS.100).aspx
You might need to inherit from the designer-generated classes instead.
EDIT: Just looked at some VS2010-generated DataSet classes, and they are indeed partial, so assuming you are using .NET 4, yours should be partial as well. I'll investigate further.
FURTHER EDIT:
OK, since the designer creates the *DataTable classes as nested classes within a class that inherits from DataSet, you might need to do the same in your partial class:
That seems to work for me.
似乎我刚刚使用错误的标识符扩展了我的类:
有一个
命名空间
,命名空间内部是部分公共类
。因此我的代码:是错误的......我需要的是:
It seems as though I've just extended my class using the wrong identifiers:
There is a
Namespace
and inside of the namespace is thePartial Public Class
. Therefore my code of:was wrong...What I needed was: