This project is read-only.

Multiple Primary Keys + Relation

Feb 23, 2010 at 1:32 PM
Edited Feb 23, 2010 at 1:33 PM

I know i can define a composite primary key by just added the Identifier = True Attribute to the Field declaration, but how would a set the Relation when this is needed for a foreignkey?

So basicly, how would I define composite foreignkeys.

 

Greetings

Feb 23, 2010 at 6:13 PM

Just like so. For a one-to-many relationship it looks like this

 

[Relation("Id=HouseId", PersistRelationship = PersistRelationships.ParentFirst)]
private ObjectSetHolder<Seasons> _SeasonsRelation = new ObjectSetHolder<Seasons>();
public ObjectSet<Seasons> SeasonRelation
{
    get { return _SeasonsRelation.InnerObject; }
    set { _SeasonsRelation.InnerObject = value; }
}

 

For a  one-to-one relationship it looks like this

[Relation("Id=HouseId", PersistRelationship = PersistRelationships.ParentFirst)]
private ObjectHolder<Seasons> _SeasonsRelation = new ObjectHolder<Seasons>();
public Seasons SeasonRelation
{
    get { return _SeasonsRelation.InnerObject; }
    set { _SeasonsRelation.InnerObject = value; }
}
Hope this helps!

Feb 24, 2010 at 7:24 AM

What if I have a multicolumn primarykey linked with a multicolumn foreignkey for example. 

 Employees
   PK : EmployeeCode
   PK : FileCode 
   ... More fields

 EmployeeAbsences
   PK : EmployeeCode
   PK : FileCode
   PK : Serial
   ... More fields

FOREIGN KEY (EmployeeCode, FileCode) REFERENCES Employees (EmployeeCode, FileCode))

 

Mar 2, 2010 at 4:14 PM

I don't think it's possible. Sounds like a good feature request though! With a little modification the Relation attribute class could handle something like that by maybe comma separating the columns.

Relation("EmployeeCode,FileCode=EmployeeCode,FileCode")

Mar 4, 2010 at 3:50 AM
Edited Mar 4, 2010 at 3:51 AM

You can address this scenario it right now.  It works like this:

[Relation("Id1 = ForeignKeyId1; Id2 = ForeignKeyId2")]

Cheers,
Christian

Mar 4, 2010 at 7:01 AM

What a blast, guess the documentation didn't quite explain this. Such a shame :)

Thank you for the help
Ontani

Mar 5, 2010 at 3:54 AM

Hi Ontani, I took this sample from the documentation samples on the RelationAttribute class. It has also other samples on how to use it :)

Mar 10, 2010 at 9:07 AM
Edited Mar 10, 2010 at 9:08 AM

Ok I've implemented the suggested method, but i'm getting the following error: 

Mapping.RelationsParserException : {"Parent object member is not found in <ProjectName>.KleurCodes"}

<Persistent("EK008")> _
Public Class KleurCodes
	Inherits BaseModel
	
	<Relation("CDAFW = KUAFW; KUKLR = CDKLR; KUOPP = CDOPP")> _
	Private _OrdersSet As New ObjectSetHolder(Of Orders)

	<Relation("CDAFW = VUAFW; VUKLR = CDKLR; VUOPP = CDOPP")> _
	Private _OrdersVUAFWSet As New ObjectSetHolder(Of Orders)

	<Relation("CDAFW = KIAFW; KIKLR = CDKLR; KIOPP = CDOPP")> _
	Private _OrdersKIAFWSet As New ObjectSetHolder(Of Orders)

	<Relation("CDAFW = VIAFW; VIKLR = CDKLR; VIOPP = CDOPP")> _
	Private _OrdersVIAFWSet As New ObjectSetHolder(Of Orders)

	Private _CDAFW as String
	<Field("CDAFW", AllowDBNull:=False)> _
	Public Property CDAFW As String
		Get
			Return Me._CDAFW
		End Get
		Set(ByVal value as String)
			Me._CDAFW = value
		End Set
	End Property

	Private _CDKLR as String
	<Field("CDKLR", AllowDBNull:=False)> _
	Public Property CDKLR As String
		Get
			Return Me._CDKLR
		End Get
		Set(ByVal value as String)
			Me._CDKLR = value
		End Set
	End Property

	Private _CDOPP as String
	<Field("CDOPP", AllowDBNull:=False)> _
	Public Property CDOPP As String
		Get
			Return Me._CDOPP
		End Get
		Set(ByVal value as String)
			Me._CDOPP = value
		End Set
	End Property

	Public Property OrdersSet As ObjectSet(Of Orders)
		Get
			Return Me._OrdersSet.InnerObject
		End Get
		Set(ByVal value as ObjectSet(Of Orders))
			Me._OrdersSet.InnerObject = value
		End Set
	End Property

	Public Property OrdersVUAFWSet As ObjectSet(Of Orders)
		Get
			Return Me._OrdersVUAFWSet.InnerObject
		End Get
		Set(ByVal value as ObjectSet(Of Orders))
			Me._OrdersVUAFWSet.InnerObject = value
		End Set
	End Property

	Public Property OrdersKIAFWSet As ObjectSet(Of Orders)
		Get
			Return Me._OrdersKIAFWSet.InnerObject
		End Get
		Set(ByVal value as ObjectSet(Of Orders))
			Me._OrdersKIAFWSet.InnerObject = value
		End Set
	End Property

	Public Property OrdersVIAFWSet As ObjectSet(Of Orders)
		Get
			Return Me._OrdersVIAFWSet.InnerObject
		End Get
		Set(ByVal value as ObjectSet(Of Orders))
			Me._OrdersVIAFWSet.InnerObject = value
		End Set
	End Property

End Class

<Persistent("EC001")> _
Public Class Orders
	Inherits BaseModel

	<Relation("KUAFW = CDAFW; KUKLR = CDKLR; KUOPP = CDOPP", PersistRelationship:=PersistRelationships.ChildFirst)> _
	Private _kleurcodesKUAFW As New ObjectHolder(Of KleurCodes)

	<Relation("VUAFW = CDAFW; VUKLR = CDKLR; VUOPP = CDOPP", PersistRelationship:=PersistRelationships.ChildFirst)> _
	Private _kleurcodesVUAFW As New ObjectHolder(Of KleurCodes)

	<Relation("KIAFW = CDAFW; KIKLR = CDKLR; KIOPP = CDOPP", PersistRelationship:=PersistRelationships.ChildFirst)> _
	Private _kleurcodesKIAFW As New ObjectHolder(Of KleurCodes)

	<Relation("VIAFW = CDAFW; VIKLR = CDKLR; VIOPP = CDOPP", PersistRelationship:=PersistRelationships.ChildFirst)> _
	Private _kleurcodesVIAFW As New ObjectHolder(Of KleurCodes)

	Private _ORDNR as String
	<Field("ORDNR", AllowDBNull:=False)> _
	Public Property ORDNR As String
		Get
			Return Me._ORDNR
		End Get
		Set(ByVal value as String)
			Me._ORDNR = value
		End Set
	End Property

	Private _FASE as String
	<Field("FASE", AllowDBNull:=False)> _
	Public Property FASE As String
		Get
			Return Me._FASE
		End Get
		Set(ByVal value as String)
			Me._FASE = value
		End Set
	End Property

	Private _REFER as String
	<Field("REFER")> _
	Public Property REFER As String
		Get
			Return Me._REFER
		End Get
		Set(ByVal value as String)
			Me._REFER = value
		End Set
	End Property

	Private _KUAFW as String
	<Field("KUAFW")> _
	Public Property KUAFW As String
		Get
			Return Me._KUAFW
		End Get
		Set(ByVal value as String)
			Me._KUAFW = value
		End Set
	End Property

	Private _KUKLR as String
	<Field("KUKLR")> _
	Public Property KUKLR As String
		Get
			Return Me._KUKLR
		End Get
		Set(ByVal value as String)
			Me._KUKLR = value
		End Set
	End Property

	Private _KUOPP as String
	<Field("KUOPP")> _
	Public Property KUOPP As String
		Get
			Return Me._KUOPP
		End Get
		Set(ByVal value as String)
			Me._KUOPP = value
		End Set
	End Property

	Private _VUAFW as String
	<Field("VUAFW")> _
	Public Property VUAFW As String
		Get
			Return Me._VUAFW
		End Get
		Set(ByVal value as String)
			Me._VUAFW = value
		End Set
	End Property

	Private _VUKLR as String
	<Field("VUKLR")> _
	Public Property VUKLR As String
		Get
			Return Me._VUKLR
		End Get
		Set(ByVal value as String)
			Me._VUKLR = value
		End Set
	End Property

	Private _VUOPP as String
	<Field("VUOPP")> _
	Public Property VUOPP As String
		Get
			Return Me._VUOPP
		End Get
		Set(ByVal value as String)
			Me._VUOPP = value
		End Set
	End Property

	Private _KIAFW as String
	<Field("KIAFW")> _
	Public Property KIAFW As String
		Get
			Return Me._KIAFW
		End Get
		Set(ByVal value as String)
			Me._KIAFW = value
		End Set
	End Property

	Private _KIKLR as String
	<Field("KIKLR")> _
	Public Property KIKLR As String
		Get
			Return Me._KIKLR
		End Get
		Set(ByVal value as String)
			Me._KIKLR = value
		End Set
	End Property

	Private _KIOPP as String
	<Field("KIOPP")> _
	Public Property KIOPP As String
		Get
			Return Me._KIOPP
		End Get
		Set(ByVal value as String)
			Me._KIOPP = value
		End Set
	End Property

	Private _VIAFW as String
	<Field("VIAFW")> _
	Public Property VIAFW As String
		Get
			Return Me._VIAFW
		End Get
		Set(ByVal value as String)
			Me._VIAFW = value
		End Set
	End Property

	Private _VIKLR as String
	<Field("VIKLR")> _
	Public Property VIKLR As String
		Get
			Return Me._VIKLR
		End Get
		Set(ByVal value as String)
			Me._VIKLR = value
		End Set
	End Property

	Private _VIOPP as String
	<Field("VIOPP")> _
	Public Property VIOPP As String
		Get
			Return Me._VIOPP
		End Get
		Set(ByVal value as String)
			Me._VIOPP = value
		End Set
	End Property

	Public Property KleurCodesKUAFW as KleurCodes
		Get
			Return Me._kleurcodesKUAFW.InnerObject
		End Get
		Set(ByVal value as KleurCodes)
			Me._kleurcodesKUAFW.InnerObject = value
		End Set
	End Property

	Public Property KleurCodesVUAFW as KleurCodes
		Get
			Return Me._kleurcodesVUAFW.InnerObject
		End Get
		Set(ByVal value as KleurCodes)
			Me._kleurcodesVUAFW.InnerObject = value
		End Set
	End Property

	Public Property KleurCodesKIAFW as KleurCodes
		Get
			Return Me._kleurcodesKIAFW.InnerObject
		End Get
		Set(ByVal value as KleurCodes)
			Me._kleurcodesKIAFW.InnerObject = value
		End Set
	End Property

	Public Property KleurCodesVIAFW as KleurCodes
		Get
			Return Me._kleurcodesVIAFW.InnerObject
		End Get
		Set(ByVal value as KleurCodes)
			Me._kleurcodesVIAFW.InnerObject = value
		End Set
	End Property

End Class

 

 

Mar 11, 2010 at 10:23 AM

My auto-generator did something wrong... 

<Relation("CDAFW = KUAFW; KUKLR = CDKLR; KUOPP = CDOPP")> _
had to be
<Relation("CDAFW = KUAFW; CDKLR = KUKLR; CDOPP = KUOPP")> _
Got it fixed by now.