I'm creating AF attributes and populating it's limits from a legacy SQL based system; appreciate if someone could guide me on how to link the AFAttributeTrait object with an AFAttribute.
Since the title has programaticaly: are you working with specific code? If so, what language/environment? Do you already know how to use the Table Lookup Data Reference (TLDR) to associate a given SQL limit with an AFAttribute, and you want to know how to specify that that AFAttribute is a particular limit Trait to another AFAttribute?
Do you intend to use a linked AFTable to a View back in the legacy SQL based system? Or is this a 1-off app where you will open the SQL View to assign static values to each attribute limit, and your AFDatabase will not have a linked AFTable?
If you plan on using a linked AFTable, can you tell us more about the columns and what about which row filtering you plan on using for the TLDR? If I were using an AFTable, I would try to have my view with 4 limit columns (names not important but separate columns for Lo, Hi, LoLo, and HiHi). There are other columns that would help me filter to a specific row. That is if I am in Plant A, Unit B, Equipment C, and I want to map to my Widgets measurement, I need columns in my view so that I can filter down to just that. That means my view needs at least 4 more columns for me to filter down to Widgets, plus you may also have a time column if your table will have a very tiny bit of history - and I cannot emphasize tiny enough. Then the linking of limits to traits can be done quite easily by modifying the element template. The key to all this is taking advantage of the best that AF has to offer with templates and naming patterns.
If you are planning a 1-off app, then I would suggest performance would be far better and your database more flexible, if you were to migrate the SQL limits to be PI tags. This gives a great boost for history of limits, and a change of limit from PI tags can be used to trigger analyses.
The big picture of what you want is easy to understand, but it doesn't provide enough to offer you a meaningful direction. If you tell us more about your use-case, we can be more focused in answers.
Actually it's a 1-off app to read the limits from the legacy and create Limit traits for the attributes, and this will be a small C# console app. Thanks for the more info you shared and I see the benefits of each approach.
I am going to assume you have no problem programmatically reading tables or views from your legacy SQL system. You may be doing this using a linked AFTable, or you may have your app connect to your SQL system and access a view as a DataTable. But you haven't indicated that this is a concern, so I again assume you have access to the data within your Console app.
Is there a timestamp associated with a limit row in your SQL view? That is was there history with your SQL limits? If yes, then what time zone does that timestamp represent?
Will the Limit Trait Attributes be static attributes? Or will the Limit Trait Attributes be mapped back to PIPoints?
Are you using element templates? If yes, then have all the Limit Traits been defined to the element templates? If yes, then you don't need to programmatically create the Limit Traits, but rather your task is to populate them with values. And how you populate them with values depends upon whether they are static attributes or not, and whether there is a timestamp to import.
How ambitious do you intend for you app to be? Do you expect it to pass over all your limit rows and try to detect which tags have which limits? This may be tough to do with element templates. Not impossible, mind you, but the code must be careful, exhaustive, and well thought out. Or are you not using templates, so the next phase would be to loop over every element to check every attribute, and if that attribute is mapped to a tag in your list that your code would then create a new Limit Trait attribute and assign a value to it.
Keep in mind that AF works best when using templates. There is so much performance efficiencies around templates.
Take a look at this blog and let us know if you have any questions: New Attributes Traits
Essentially, each AFAttribute has a trait property that you can set to the desired trait such as AFAttributeTrait.LimitHi.
Retrieving data ...