Active Query Builder support area

ForeignKey added via code does not work

Avatar
  • updated
  • Completed
I add a foreignkey via code in Metatadacontainer, but once I add TableA and TableB the link is not created.

If I see the metadata via EditMetadataContainer I can see on TableA the  MyforeignkytoB, but seems that the two fields are not linked.  

What's wrong ?

thanks
Avatar
Vincenzo
Yes, that fixed the problem. Thanks
Avatar
Andrey Zavyalov, PM
Change "r.AddField( "Data1" )" to "r.Fields.Add( "Data1" )". This will fix the problem.
Avatar
Vincenzo
ok let me know if you need a small program that reproduce the error.

I create the metadatacontainer all by code.
Avatar
Andrey Zavyalov, PM
We need some time in order to reproduce the problem. One more question: how do you add tables: using the component's UI or programmatically?
Avatar
Vincenzo
nope...   same behavior :(   metadata knows that there a link between the two tables, but do not know which fileds are involved.
 
Avatar
Andrey Zavyalov, PM
try to change the "r.ReferencedObjectName = name" to "r.ReferencedObject = t"
Avatar
Vincenzo
before the beginupdate are missing those lines...

qb.OfflineMode = True

qb.MetadataProvider = Nothing
md = qb.MetadataContainer

Avatar
Vincenzo
ok, qb is the querybuilder

Dim md As MetadataContainer
Dim mov As MetadataObject
Dim r As MetadataForeignKey
Dim f As MetadataField

md.BeginUpdate()

'TABELLA: Movimenti
mov = md.AddTable( "Movimenti" )
mov.AltName = "Movimenti"

f = mov.AddField("Data1") : f.FieldType = DbType.Date : f.AltName = "DataCompetenza"

t = md.AddTable("Tempo") : t.AltName = "Tempo"
f = t.AddField("Giorno") : f.FieldType = DbType.Date : f.AltName = "Giorno"

r = mov.AddForeignKey( "MovimentiToTempo" )
Using name As New MetadataQualifiedName()
name.Add("Tempo")
r.ReferencedObjectName = name
End Using
r.AddField( "Data1" ) : r.ReferencedFields.Add( "Giorno" )

--------------------------------------

at the end, I can see the ForeignKey   MovimentiToTempo  but there isn't any link between the field Data1 and the field Giorno

thank you

Avatar
Andrey Zavyalov, PM
Sorry, but I can't tell you anything until see the source code of adding a foreign key. Pease post it here.