Active Query Builder support area

NonQualifiedNameNames in v3.1.1.1024

Avatar
  • updated
  • Completed

Hi,

I have a known column name, and want to find the object in the query that corresponds to that name. The name I have is not qualified but it is qualified in the sql. E.g. I have "Color" and the column in the select is "Product.Color"

I have the QueryColumnListItem-s from the select query, and want to get the unqualified name. In the past I used


CriteriaItem crit = ...

(crit.Expression as SQLExpressionColumn)?.Column?.NonQualifiedNameNames


In v3 I have

QueryColumnListItem crit = ...

//NonQualifiedNameNames doesn't exist, not sure how to use

//(crit.Expression as SQLExpressionColumn).Column.BuildNonQualifiedNameNames

//so instead...

SQLObjectColumn col = (crit.Expression as SQLExpressionColumn)?.Column;
var foo = col?.Items?.FirstOrDefault() as AstToken;
foo?.Token //contains "Color"


I worry this is a bit of a hack and won't work in some circumstances, is there a better way?

Avatar
Andrey Zavyalov, PM

Addendum: You should search for column name in the StatisticsOutputColumn.ColumnName (or FieldName).

Again, I don't understand your task in detail. May be it is better for your task to search in the UnionSubQuery.QueryColumnsList as you did that before... I don't know.

Avatar
Colin Overton

Just saw that too, I should have looked harder! :-(

Avatar
Andrey Zavyalov, PM

You wrote: "but the StatisticsDatabaseObject doesn't seem to have the data sources."

I've recommend you to use the QueryBuilderQueryStatistics.OutputColumns to find a column. Items of this collection are of the StatisticsOutputColumn type which has the DataSource property.

Avatar
Colin Overton

Ah, that's great, thanks!

What I need to do is find the DataSource for the column (which this gives me) and then remove some other data sources from the query.

I'm using:

var dataSources = firstSelect.Children.OfType<DataSourceGroup>().FirstOrDefault();

to get the data sources, then calling .Dispose() on some of them

I suspect there is a better way of doing this too, but the StatisticsDatabaseObject doesn't seem to have the data sources.

I have to admit I'm just exploring the object model in the VS visualiser to try and find what I'm after!

Thanks again for the help

Avatar
Andrey Zavyalov, PM

The best way to find database object and field by column name is to use the QueryBuilder.QueryStatistics.OutputColumns collection. Each item of this collection has references to MetadataObject, MetadataField and QueryColumnListItem (former CriteriaItem). What you need to get in result?