System.Data.Function 在此上下文中不可用,因为它是“Friend”;

发布于 2024-10-19 08:56:55 字数 682 浏览 0 评论 0原文

我目前正在尝试使用解决方案 here,但是,当将分部类添加到我的 DataContext.vb 或单独的 DataContextPartial.vb 时,我收到错误 System.Data.Function 不可用在这种情况下,因为它是“朋友”

我之前在访问数据类型时遇到过这种情况,只需将其设置为 Public 即可轻松修复,但我不确定 function 的属性可能在哪里或如何更改它们。

我的代码已从上面链接答案中的 C# 转换为 VB.NET:

Partial Public Class CMSModelDataContext
    <[Function](Name:="NEWID", IsComposable:=True)> _
    Public Function Random() As Guid
        Throw New NotImplementedException()
    End Function
End Class

感谢您提前提供的任何帮助。

I'm currently trying to create a NEWID() function in my DataContext in LINQ using the solution here, however, when adding the partial class to my DataContext.vb or a separate DataContextPartial.vb, I get the error System.Data.Function is not available in this context because it is 'Friend'.

I've come across this when accessing data types before and that was in easy fix of setting it to Public, but I'm not sure where the properties for function could be or how to change them.

The code I have is converted to VB.NET from the C# in the linked answer above:

Partial Public Class CMSModelDataContext
    <[Function](Name:="NEWID", IsComposable:=True)> _
    Public Function Random() As Guid
        Throw New NotImplementedException()
    End Function
End Class

Thanks for any help in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

顾忌 2024-10-26 08:56:55

我立即记不起 VB 是否自动应用“属性”后缀。请尝试以下操作:

<FunctionAttribute(Name:="NEWID", IsComposable:=True)>

...并确保您已导入 System.Data.Linq.Mapping

编辑:看起来 VB 确实应用了 Attribute 后缀,所以我怀疑您缺少导入或引用。但是,显式指定 FunctionAttribute 至少可以帮助您通过消除 System.Data.Function 的“误报”来验证这一点。

I can't remember offhand whether VB applies the "Attribute" suffix automatically. Try this instead:

<FunctionAttribute(Name:="NEWID", IsComposable:=True)>

... and make sure you have an import for System.Data.Linq.Mapping.

EDIT: It looks like VB does apply the Attribute suffix, so I suspect you were missing an import or a reference. However, specifying FunctionAttribute explicitly will at least help you to verify this by removing the "false positive" of System.Data.Function.

何必那么矫情 2024-10-26 08:56:55

我相信你应该

Import System.Data.Linq.Mapping

因为 FunctionAttribute驻留在那里。

您没有导入名称空间,编译器会以错误的方向查找类。尽最大努力并看到您已导入 System.Data,编译器假设您想要使用 System.Data.Function 这是一个内部(Friend) System.Data.dll 程序集中的类,因此出现错误。

人们可能想知道此错误消息的确切目的是什么。如果无论如何都无法访问该类,为什么还要费心去讲述它呢?我认为原因是您可能引用了自己的程序集而忘记将某些类型设为公共。编译器警告您它看到该类,但您只是无法使用它,这是有道理的。对所有引用(包括框架库)应用相同的规则也是有意义的,尽管显然您不能修改其中的任何内容。

我认为 FunctionAttribute 并不是一个特别好的名称选择,因为它会导致错误的命名空间导入和相关的混乱。

I believe you should

Import System.Data.Linq.Mapping

because FunctionAttribute resides there.

You didn't import the namespace, and compiler went to look for the class in the wrong direction. Trying its best and seeing that you have imported System.Data, compiler assumed you want to use System.Data.Function which is an internal (Friend) class in System.Data.dll assembly, hence the error.

One can wonder what exactly is the purpose of this error message. If the class isn't accessible anyway, why even bothering to tell about it? I think the reason is you could've referenced your own assembly forgetting to make some of types Public. It makes sense that compiler warns you that it sees the class but you just can't use it. It also makes sense applying same rules to all references, including framework libraries, although obviously you can't modify anything in there.

I would argue that FunctionAttribute is not a particularly good choice of name because it's begging for wrong namespace imports and related confusion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文