LINQ to SQL 类不符合 CLS?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它最终取决于数据库返回的类型以及这些类型的名称。
有关 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.
我在 MSDN Connect 上找到了此链接:
如果要消除警告,可以使用:
或者,如果要在项目范围内禁用它们,请将 3021 添加到 Visual Studio 中项目属性的“生成”选项卡中的“抑制警告”字段。
I found this link on MSDN Connect:
If you want to get rid of the warnings, you can use:
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.
Ben M 对这个问题的想法是正确的。
在 VB.Net 项目上解决此问题的最快方法是使程序集不符合 CLSCompliant,从而避免出现这些警告。 将以下行添加到任何文件中都可以解决问题,
将其添加到的最佳文件是“我的项目”文件夹内的 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
Best file to add it into is AssemblyInfo.vb inside of the "My Project" folder.
当我使用一个程序集中没有 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?