Book a Demo

Author Topic: Getting Primary-/ForeignKey from DataModel objects  (Read 3703 times)

Chris Meyer

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Getting Primary-/ForeignKey from DataModel objects
« on: November 25, 2009, 08:57:12 pm »
Hi,
I'm developing an AddIn for our company to export EA diagrams to a specific format.
Actually i'm a little stuck on how to conveniently get primaryKey, foreignKey(s) and attributes (such as not null, unique, etc.) in C# from an EA.Element? And further how to get the primaryKey of the referenced table (by a foreignKey) in case i only got an EA.Element, referencing this table (other EA.Element), passed?
In the sample code such cases aren't covered, if i'm not mistaken. Unfortunately I couldn't find any API doc describing object members and routines...

Can anyone give me a hint how to face these issues?
Thanks for your effort in advance.

Regards,
Chris

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Getting Primary-/ForeignKey from DataModel obj
« Reply #1 on: November 25, 2009, 09:16:39 pm »
Chris,

What I usually do in such cases is to start with an empty model (eap file).
- Create only those elements (table, PK, FK) that you are interested in.
- Open the eap file with MS Access.
- Look in the tables to see how EA has stored the properties you are interested in.
- Find the attribute in the API that gets filled with the column from the database.

There is a big chance that they will store that kind of data in "magic string" columns such as the PDATA in the form of name/value pairs.

Geert

Chris Meyer

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Getting Primary-/ForeignKey from DataModel obj
« Reply #2 on: November 25, 2009, 09:56:53 pm »
Thanks for your reply.
I noticed the following in the attributes:

caseIsStaticAllowDuplicates
unique, not null11
unique10
not null01
nothing00

Is it possible that the isStatic and AllowDuplicates flags specify not null and unique attributes?

Regards,
 Chris

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Getting Primary-/ForeignKey from DataModel obj
« Reply #3 on: November 25, 2009, 10:23:03 pm »
Hi Chris,

IIRC that is indeed the case - but it's a few years since I looked at it.

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Chris Meyer

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Getting Primary-/ForeignKey from DataModel obj
« Reply #4 on: November 25, 2009, 10:39:05 pm »
Perfect,
thanks for your help guys!