扩展数据集类不起作用

发布于 2024-11-06 10:34:48 字数 388 浏览 4 评论 0原文

我使用数据集设计器创建了一个数据集。我的一个表名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我闹别瞎闹 2024-11-13 10:34:48

所有“部分”类都必须如此声明才能使该技术发挥作用,我猜测 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 的类中的嵌套类,因此您可能需要在部分类中执行相同的操作:

public partial class UsersData
{
    public partial class UsersDataTable
    {
        public string Foo { get; set; }
    }
}

这似乎对我有用。

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:

public partial class UsersData
{
    public partial class UsersDataTable
    {
        public string Foo { get; set; }
    }
}

That seems to work for me.

冷︶言冷语的世界 2024-11-13 10:34:48

似乎我刚刚使用错误的标识符扩展了我的类:

有一个命名空间,命名空间内部是部分公共类。因此我的代码:

Partial Public Class myData
    Partial Public Class UsersTableAdapter
        Public Function DoSomething() As String
            Return "Testing..."
        End Function
    End Class
End Class

是错误的......我需要的是:

Namespace myDataTableAdapters
    Partial Public Class UsersTableAdapter
        Public Function DoSomething() As String
            Return "Testing..."
        End Function
    End Class
End Namespace

It seems as though I've just extended my class using the wrong identifiers:

There is a Namespace and inside of the namespace is the Partial Public Class. Therefore my code of:

Partial Public Class myData
    Partial Public Class UsersTableAdapter
        Public Function DoSomething() As String
            Return "Testing..."
        End Function
    End Class
End Class

was wrong...What I needed was:

Namespace myDataTableAdapters
    Partial Public Class UsersTableAdapter
        Public Function DoSomething() As String
            Return "Testing..."
        End Function
    End Class
End Namespace
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文