简体   繁体   中英

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. But doing this as created numerous compilation errors in the generated code.

In the file FirstDB.designer.vb the errors are:-

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:-

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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