I'd like to compose a query to use with DgnECManager.FindInstances using an ECQuery. Unfortunately, the MstnPlatformNet documentation continues to ignore that class. The SDK examples help little, using the catch-all SelectAllProperties.
DgnECManager.FindInstances
ECQuery
SelectAllProperties
ECQuery query = new ECQuery(GetSearchClasses()); query.SelectClause.SelectAllProperties = true;
How can one write a query, say, to select Item instance properties having a certain value? That is, I'd like to know about ECQuery.SelectClause. If Item Types supported SQL, I would write something like...
ECQuery.SelectClause
SELECT * FROM MyItemType WHERE ID='abc'
Since DgnECManager.FindInstances returns IQueryable<> it's tempting to ignore the MstnPlatformNet API and use LINQ to compose a query. Which approach would you make your strategy?
IQueryable<>
Hi Jon,
I apologize for joining this thread late.
About .NET ECQuery documentation: I am trying to get whole bunch of .NET ECFramework documentation in U13 SDK. Robert Hook will let you know accordingly.
About using .NET ECQuery:
In ECQuery.SelectClause,
You call tell which properties you want: query.SelectClause.SelectedProperties.Add(..
You can tell what relationships you want w.r.t. searchClasses as:
QueryRelatedClassSpecifier relClassSpec = new QueryRelatedClassSpecifier (m_relationshipClass, false, ECI.RelatedInstanceDirection.Forward, m_targetClass, false); RelatedCriterion relatedPropertyCriterion = new RelatedCriterion (relClassSpec);
query.SelectClause.SelectedRelatedInstances.Add (new RelatedInstanceSelectCriteria (relClassSpec, true));
Please let me know if you are looking for something else.
Thanks,
Mangesh
Mangesh.Shelar said:I am trying to get whole bunch of .NET ECFramework documentation in U13 SDK
Excellent!
Mangesh.Shelar said:You can tell what relationships you want
At this point I'm looking at simple queries that concern a single Item Type and its properties. For example, suppose I want to query my AreaAnnotator Item Type, I want to write something similar to SQL statement...
SELECT ID, RoomType, occupied FROM 'Area Feature' WHERE occupied = True AND RoomType = 'Office'
That would evolve into a relationship when I want to get the area of the DGN element that is tagged with that Item Type...
SELECT ID, RoomType, occupied, Element.Area FROM 'Area Feature', Element WHERE occupied = True AND RoomType = 'Office' AND Element.Area > 500
FWIW I already wrote, with Paul Connelly's help, a C# demo that implements an EC relationship to harvest tag elements.
Regards, Jon Summers LA Solutions
For comparison, and possibly inspiration, here's how I create an ECQuery using C++...
bool ECQueryFactory::ComposeCriteria (ECQueryPtr query, WCharCP property, WCharCP filter) { using namespace Bentley::DgnPlatform; // Property 'all' is a pseudo-property meaning 'find all instances' if (0 == wcsicmp (L"all", property)) return true; const bool AcceptAll { (nullptr == filter || 0 == wcslen (filter) || L'*' == *filter) }; bool composed { false }; if (query.IsValid()) { WhereExpressionPtr expression { WhereExpression::CreatePropertyExpression (property) }; const bool& IfMatch { true }; const bool& CaseSensitive { false }; WhereCriterionPtr where; WhereCriterion::StringFilterError error; if (!AcceptAll) { if (RegEx::IsRegEx (filter)) { where = WhereCriterion::CreateRegexFilter (&error, *expression, filter, CaseSensitive); } else { where = WhereCriterion::CreateStringFilter(&error, *expression, filter, IfMatch, CaseSensitive); } } if (!where.IsValid () && WhereCriterion::STRING_FILTER_ERROR_InvalidSyntax == error) { CMessageTracer moan (__FUNCTION__ L": CreateStringFilter syntax error filter="); moan.Quote (filter); moan.Advisory (); } else { if (!AcceptAll) { query->SetWhereCriterion (*where); } composed = query.IsValid (); } } return composed; }
Classes ECQuery, WhereExpression and WhereCriterion are documented in MicroStationAPI help. The documentation is terse, with no explanation about how to use those methods. But at least it's available!
WhereExpression
WhereCriterion
Hi Jon Summers,
FWIW. We are actively looking to packages some more EC API documentation (in current form) in the MicroStation SDK and once delivered we can try to advance EC API docs with appropriate Getting Started info and example(s), and possible "Explorer" app. I have been trying to introduce these concepts more and more as we move things forward. Thank you for your always helpful code snips and posts!
Bob