I thought I understood from experience how to do many-to-one relationships and from the documentation how to attempt a many-to-many relationship. Unfortunately, things are not working at the moment. If I comment out the property/relationship State.Cities
, remove the Association
declaration from City.State
, and comment out both sides of the many-to-many relationship between ZipCode
and AreaCode
then my website builds. If I do not, then during Domain.Build()
I get:
Item with key 'Fields' was not found. You might have forgotten to apply [Field] attribute on property Fields.State
.
OR
Field 'ZipCode.AreaCodes' is already paired with 'AreaCode.ZipCodes'. Please remove [Association] attribute at 'AreaCode.ZipCodes'.
I am particularly confused as to why Country->States
works but State->ZipCodes
does not. I was trying to learn how to use a many-to-many relationship from linq-many-to-many-relationship topic @ support and documentation
I am working with a legacy database (DomainUpgradeMode.LegacyValidate) and there is no way around that. A partial excerpt of my code base, which I hope is the relevant part, is:
<TableMapping("tblCountries")>
<HierarchyRoot(), KeyGenerator(KeyGeneratorKind.None)>
Public Class Country Inherits Entity
<Field(), Key()>
Property ID As Integer
<Field(Nullable:=False), FieldMapping("geoLocationID")>
Property GeoLocation As GeoLocation
<Field(), Association("Country")>
Property States As EntitySet(Of State)
End Class
<TableMapping("tblStates")>
<HierarchyRoot(), KeyGenerator(KeyGeneratorKind.None)>
Public Class State
Inherits Entity
<Field(), Key()>
Property ID As Integer
<Field(), FieldMapping("geoLocationID")>
Property GeoLocation As GeoLocation
<Field(Nullable:=False), FieldMapping("countryID"), Association("States")>
Property Country As Country
<Field(), Association("State")>
Property Cities As EntitySet(Of City)
End Class
<TableMapping("tblCities")>
<HierarchyRoot(), KeyGenerator(KeyGeneratorKind.None)>
Public Class City
Inherits Entity
<Field(), Key()>
Property ID As Integer
<Field(Nullable:=False), FieldMapping("geoLocationID")>
Property GeoLocation As GeoLocation
<Field(Nullable:=False), FieldMapping("stateID"), Association("Cities")>
Property State As State
End Class
<TableMapping("tblZipCodes")>
<HierarchyRoot(), KeyGenerator(KeyGeneratorKind.None)>
Public Class ZipCode
Inherits Entity
<Field(), Key()>
Property ID As Integer
<Field(Nullable:=True), FieldMapping("geoLocationID")>
Property GeoLocation As GeoLocation
<Field(), Association("ZipCodes")>
Property AreaCodes As EntitySet(Of AreaCode)
End Class
<TableMapping("tblAreaCodes")>
<HierarchyRoot(), KeyGenerator(KeyGeneratorKind.None)>
Public Class AreaCode
Inherits Entity
<Field(), Key()>
Property ID As Integer
<Field(Nullable:=False), FieldMapping("geoLocationID")>
Property GeoLocation As GeoLocation
<Field(), Association("AreaCodes")>
Property ZipCodes As EntitySet(Of ZipCode)
End Class
I have tried to post a simplified example of my problem. If the full code is needed to diagnose the issue then I can make it available in a zip archive. If there are any other questions I can answer or information I can provide about what I am trying to do or how I am trying to do it, please let me know. Thank you very much for your time and assistance.
asked
Feb 14 '12 at 11:43
GigMastersTech
27●11●11●15