简体   繁体   English

两个具有LINQ的数据库-生成的代码中的编译错误

[英]Two Databases with LINQ - Compilation errors in generated code

I have added LINQ-to-SQL classes to two different databases in a single VB.Net project. 我在一个VB.Net项目中将LINQ-to-SQL类添加到了两个不同的数据库中。 But doing this as created numerous compilation errors in the generated code. 但是这样做会在生成的代码中产生许多编译错误。

In the file FirstDB.designer.vb the errors are:- 在文件FirstDB.designer.vb中,错误是:

2 of: 'Protected Overridable Sub SendPropertyChanged(propertyName As String)' has multiple definitions with identical signatures.
2 of: 'Protected Overridable Sub SendPropertyChanging()' has multiple definitions with identical signatures.
2 of: 'Public Sub New()' has multiple definitions with identical signatures.

In the file SecondDB.designer.vb the errors are:- 在文件SecondDB.designer.vb中,错误是:

2 of: 'emptyChangingEventArgs' is already declared as 'Private Shared emptyChangingEventArgs As System.ComponentModel.PropertyChangingEventArgs' in this class.
2 of: 'PropertyChanged' is already declared as 'Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs)' in this class.
2 of: 'PropertyChanging' is already declared as 'Public Event PropertyChanging(sender As Object, e As System.ComponentModel.PropertyChangingEventArgs)' in this class.
2 of: Attribute 'TableAttribute' cannot be applied multiple times.
2 of: Method 'OnCreated' cannot be declared 'Partial' because only one method 'OnCreated' can be marked 'Partial'.
2 of: Method 'OnLoaded' cannot be declared 'Partial' because only one method 'OnLoaded' can be marked 'Partial'.
2 of: Method 'OnValidate' cannot be declared 'Partial' because only one method 'OnValidate' can be marked 'Partial'.

These errors appear in the error list immediately after I save the tables in the second class. 在我将表保存在第二个类中之后,这些错误立即出现在错误列表中。 I have tried recreating both classes from scratch, and I have tried qualifying all the table names with the database name this:- 我尝试从头开始重新创建两个类,并且尝试使用数据库名称来限定所有表名:

FirstDB.dbo.mytable
SecondDB.dbo.mytable

in the properties before saving the class; 在保存类之前在属性中; there are some table names common to both databases but I believe I have qualified all of them. 这两个数据库都有一些通用的表名,但我相信我已经限定了所有这些表名。

Does anyone know what is causing this and what to do about it? 有谁知道是什么原因造成的,以及如何处理? I could in principle edit the generated files, but that seems like a large number of changes to make that could disappear at any time. 从原则上讲,我可以编辑生成的文件,但是似乎有很多更改可以随时消失。

Since asking this question I have found that including the classes for the two databases in two separate projects has cured the problem. 自问了这个问题之后,我发现在两个单独的项目中包含两个数据库的类已解决了这个问题。 I don't know what effect this would have if I attempted a Linq-to-SQL query involving both databases, but I have no plans to do that. 我不知道如果尝试同时涉及两个数据库的Linq-to-SQL查询会有什么影响,但是我没有计划这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM