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<>
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
Regards, Jon Summers LA Solutions
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