LINQ to SQL 类不符合 CLS?

发布于 2024-07-30 03:57:18 字数 288 浏览 3 评论 0原文

我正在使用 LINQ to SQL 作为新项目的数据访问层。 我已将数据库表添加到设计器中,一切正常。

每当我在函数中使用这些类之一时,Visual Studio 都会警告我“类型 xxxx 不符合 CLS”或“函数 xxxx 的返回类型不符合 CLS”,

这是 LINQ to SQL 的类的问题吗?生成? 这重要吗? 我可以在任何地方禁用这些警告吗? 我的 VS 错误列表被这些警告堵塞,很难看到其他内容。

编辑:

抱歉,我应该提到这些是 VB.NET 项目。 :)

I'm using LINQ to SQL as my data access layer for a new project. I have added my database tables to the designer and all is well.

Whenever I use one of these classes in a function, Visual Studio warns me that 'Type xxxx is not CLS-compliant' or that 'Return type of function xxxx is not CLS-compliant'

Is this a problem with the classes that LINQ to SQL generates? Does it matters? Can I disable these warnings anywhere? My VS error list is clogged up with these warnings making it hard to see anything else.

EDIT:

Sorry, I should have mentioned these are VB.NET projects. :)

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

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

发布评论

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

评论(4

゛时过境迁 2024-08-06 03:57:18

它最终取决于数据库返回的类型以及这些类型的名称。

有关 CLS 合规性的一个问题是具有两个公开暴露的成员的类型,这两个成员仅在名称上有所不同,例如 MyField 和 myField。

这是一篇文章,应该帮助您确定 CSS 合规性问题发生的位置并处理这些问题。 如果您需要更多帮助,请提供一些代码,我们将看看我们能做什么。

It ultimately depends on what types are being returned by your database and what the names of those types are.

One issue regarding CLS compliance is a type that has two publicly exposed members which differ in name only by case, e.g. MyField and myField.

Here's an article that should help you determine where your CSS compliance issues are occuring and deal with the issues. If you need more help, pose some code and we'll see what we can do.

转身以后 2024-08-06 03:57:18

我在 MSDN Connect 上找到了此链接:

添加继承关系时
O/R 设计器中的类之间,
生成的访问级别
Id 的后备存储成员
属性“_Id”更改自
private 到 protected,导致 CLS
违反规则。 Id 属性是
用于之间的关联
类。

如果要消除警告,可以使用:

#pragma warning disable 3021

或者,如果要在项目范围内禁用它们,请将 3021 添加到 Visual Studio 中项目属性的“生成”选项卡中的“抑制警告”字段。

I found this link on MSDN Connect:

When adding inheritance relations
between classes in the O/R designer,
the acess level on the generated
backing store member of the Id
attribute, "_Id", is changed from
private to protected, causing the CLS
rule violation. The Id property is
used in an association between the
classes.

If you want to get rid of the warnings, you can use:

#pragma warning disable 3021

Or, if you want to disable them project-wide, add 3021 to the "Suppress warnings" field in the Build tab of your project's properties in Visual Studio.

话少情深 2024-08-06 03:57:18

Ben M 对这个问题的想法是正确的。

在 VB.Net 项目上解决此问题的最快方法是使程序集不符合 CLSCompliant,从而避免出现这些警告。 将以下行添加到任何文件中都可以解决问题,

<Assembly: CLSCompliant(False)>

将其添加到的最佳文件是“我的项目”文件夹内的 AssemblyInfo.vb。

Ben M has the right idea on the problem.

The quickest way to solve this on a VB.Net project is to make the assembly not CLSCompliant and hence avoid those warnings. Adding the following line to any of your files will do the trick

<Assembly: CLSCompliant(False)>

Best file to add it into is AssemblyInfo.vb inside of the "My Project" folder.

白日梦 2024-08-06 03:57:18

当我使用一个程序集中没有 CLSCompliant 属性确实如此。

也就是说,您的 Linq to SQL 类与您正在编写的函数是否位于不同的项目中? 您是否在解决方案中的部分项目(而非全部项目)中指定了 [assemble: CLSCompliant(true)]

I usually see that error when I'm consuming types from one assembly which does not have the CLSCompliant attribute in another assembly which does.

That is, are your Linq to SQL classes in a different project than the functions you're writing? Have you specified [assembly: CLSCompliant(true)] in some but not all of the projects in your solution?

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