4 Replies Latest reply on Mar 13, 2019 7:10 PM by Dava

    Get the Table Name form an Attribute as table lookup

    Dava

      Hi guys,

      I'm using the PI AFSDK, and I'm reading and AFAttribute as a table lookup

      And I want to get the table name configurated in it.

      Searching from properties in the debug view in Visaul Studio I found this one:

      But I was not able to get from the code, When I add this property to the watch I notice the name and other details:

      ((OSIsoft.AF.Asset.DataReference.TableLookupDR)AFAttr.DataReference).Table

      I notice this property is because the dataReference is a Table lookup.

       

      I try to get it from code And I was not able to do it, I try someting like this

       

      AFAttribute AFAttr = AFElemt.Attributes[AttrName];
      AFAttr.DataReference.table
      
      

       

      But I was not able to get the table name

      Can any give me a hand

       

      best regards

       

        • Re: Get the Table Name form an Attribute as table lookup
          Rick Davin

          Hi David,

           

          The sticking point is the DataReference property will return an AFDataReference object, which gives you the generic properties and methods of AFDataReference.  To get the Table property of the Table Lookup Data Reference, you need to either know the exact type of TLDR, or at least use a dynamic variable.

           

          The snippet of AFAttr.DataReference.returns an AFDataReference.  It would be the same as:

           

          AFDataReference dr1 = AFAttr.DataReference;
          

           

          So dr1 does not appear to have a Table property because the AFDataReference does not have a Table property.  The way to fix it would be using dynamic:

           

          dynamic dr2 = AFAttr.DataReference;
          

           

          And now it should have the Table property.  But Intellisense does not kick in with dynamic, so you do lose that feature.

            • Re: Get the Table Name form an Attribute as table lookup
              Dava

              Thanks for the reply. The dynamic approach  work:

              1. dynamic dr2 = AFAttr.DataReference; 

              You also mention "To get the Table property of the Table Lookup Data Reference, you need to either know the exact type of TLDR,..."

              I know for sure this attribute I'm reading is a tableLookup.

              So, what will be this other approach  you mention.

              How I set up the DataReference as a TLDR

               

              Best Regards

               

               

                • Re: Get the Table Name form an Attribute as table lookup
                  Rick Davin

                  The attribute you are reading is an AFAttribute.  We know that.  It's data reference is the Table Lookup Data Reference.  We know that too.  While the TLDR implements AFDataReference, it nonetheless is its own type.  The actual data type of the Table Lookup Data Reference is OSIsoft.AF.Asset.DataReference.TableLookupDR.  But that type is not baked into AF SDK. That type is not added until runtime, since after all the DR is a plug in.  Since you do not know of that type during design or compile time, you cannot use the exact type.  Instead you must use dynamic.

                   

                  If you set a breakpoint and examine the Locals window, you can see the types.  Variable dr1 was defined using var (same as AFDataReference) but variable dr2 was defined as dynamic.

                   

                  2019-03-13 14_58_36-Window.png

                  2 of 2 people found this helpful