Book a Demo

Author Topic: Primary keys and columns  (Read 5778 times)

rmartinezb

  • EA User
  • **
  • Posts: 44
  • Karma: +1/-0
    • View Profile
Primary keys and columns
« on: May 04, 2016, 06:59:02 pm »
Hi,

I'm developing an Addin in C# (only for learning purposes) in which i read a JSON chain and then create a table.
My problem is that when i create the PK i dont know how to add the pk column to it.
Here is my code:

Code: [Select]
           EA.Package thePackage = Repository.GetTreeSelectedPackage();

            if (thePackage != null && thePackage.ParentID != 0 && allGoesWell) {

                EA.Collection elements = thePackage.Elements;

                string issuename = response.IssueDescriptions[0].Fields.Project.Name + "-" +response.IssueDescriptions[0].Key + "-" + response.IssueDescriptions[0].Id;

                EA.Element theElement = elements.AddNew(issuename, "Class");
                theElement.Stereotype="Table";

                EA.Collection attributes = theElement.Attributes;
                EA.Collection methods = theElement.Methods;

                EA.Attribute newAttribute = attributes.AddNew("ID: " + response.IssueDescriptions[0].Id.ToString(), "String");
                newAttribute.Notes = response.IssueDescriptions[0].Id.ToString();
                newAttribute.Stereotype = "Column";
                newAttribute.AllowDuplicates = true;   //---> Esto indica que el atrubuto no puede ser nulo
                newAttribute.IsOrdered = true;         //---> Esto indica que el atributo es una primary key
                newAttribute.Update();
               
                EA.Method newMethod = methods.AddNew("ID: " + response.IssueDescriptions[0].Id.ToString(), "String");
                newMethod.Stereotype = "PK";

                newMethod.Update();
                methods.Refresh();

                EA.Attribute newAttribute1 = attributes.AddNew("Asignee", "string");
                newAttribute1.Notes = response.IssueDescriptions[0].Fields.Assignee.DisplayName;
                newAttribute1.Stereotype = "Column";
                newAttribute1.Update();

                EA.Attribute newAttribute2 = attributes.AddNew("Description", "String");
                newAttribute2.Notes = response.IssueDescriptions[0].Fields.Description;
                newAttribute2.Stereotype = "Column";
                newAttribute2.Update();

                EA.Attribute newAttribute3 = attributes.AddNew("Summary", "string");
                newAttribute3.Notes = response.IssueDescriptions[0].Fields.Summary;
                newAttribute3.Stereotype = "Column";             
                newAttribute3.Update();

                attributes.Refresh();

                theElement.Update();
                thePackage.Elements.Refresh();
               
            }


And some images, this is what I obtain:





And this is what I want:



Any tips?
« Last Edit: May 05, 2016, 01:57:00 am by rmartinezb »

rmartinezb

  • EA User
  • **
  • Posts: 44
  • Karma: +1/-0
    • View Profile
Re: Primary keys and columns
« Reply #1 on: May 06, 2016, 07:22:34 pm »
I'll try to give better info. I'm developing the addin with Visual Studio, this addin conects with Jira to get the JSON chan and then draw the elements on the diagram.
I need do everything by code, so although add the column to the PK is only two clicks this dont help me.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Primary keys and columns
« Reply #2 on: May 06, 2016, 09:52:15 pm »
The PK is a stereotyped operation. I don't know whether you would need a bit of salt in t_xref too. You might have to cross check that with a simple model.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Primary keys and columns
« Reply #3 on: May 07, 2016, 04:55:15 am »
What I usually do when I don't directly find where EA hides some info is to turn on the profiler on my SQL Server model.
That records every query EA executes, so it's rather easy to find what is what.

Geert