ForeignKey added via code does not work

Answered

Comments

9 comments

  • Sorry, but I can't tell you anything until see the source code of adding a foreign key. Pease post it here.
    0
    Comment actions Permalink
  • 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

    0
    Comment actions Permalink
  • Avatar
    Vincenzo
    before the beginupdate are missing those lines...

    qb.OfflineMode = True

    qb.MetadataProvider = Nothing
    md = qb.MetadataContainer

    0
    Comment actions Permalink
  • try to change the "r.ReferencedObjectName = name" to "r.ReferencedObject = t"
    0
    Comment actions Permalink
  • Avatar
    Vincenzo
    nope...   same behavior :(   metadata knows that there a link between the two tables, but do not know which fileds are involved.
     
    0
    Comment actions Permalink
  • 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?
    0
    Comment actions Permalink
  • Avatar
    Vincenzo
    ok let me know if you need a small program that reproduce the error.

    I create the metadatacontainer all by code.
    0
    Comment actions Permalink
  • Change "r.AddField( "Data1" )" to "r.Fields.Add( "Data1" )". This will fix the problem.
    0
    Comment actions Permalink
  • Avatar
    Vincenzo
    Yes, that fixed the problem. Thanks
    0
    Comment actions Permalink

Please sign in to leave a comment.