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<>
Ok, after some testing, this code seems to work:
FindInstancesScope scope2 = FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnFile(), new FindInstancesScopeOption(DgnECHostType.All, false)); IECSchema ecSchema = DgnECManager.Manager.LocateSchemaInScope(scope2, "DgnCustomItemTypes_MasterPlanner__x0020__", 1, 0, SchemaMatchType.Latest); string[] ecClassesNames = { "Something" }; var query2 = QueryHelper.CreateQuery(ecSchema, ecClassesNames); QueryHelper.WherePropertyExpressions(query2, "ID", RelationalOperator.EQ, 1); query2.SelectClause.SelectAllProperties = true; var result2 = dgnECManager.FindInstances(scope, query2);
As usually, you have to iidentify / locate:
I recommend to read a description of QueryHelper.WherePropertyExpressions method (not in help, but in xml file), because conditions/prerequisities are described here.
With regards,
Jan
P.S. Please don't ask such questions! After initial thinking "it's really interesting question, it would be nice to know also" and some playing with code ... a half of a day is just missing :-))))
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Jan Šlegr said:I recommend to read a description of QueryHelper.WherePropertyExpressions method (not in help, but in xml file)
Unfortunately...
<member name="M:Bentley.EC.Persistence.Query.QueryHelper.WherePropertyExpressions(System.Collections.Generic.IList{Bentley.ECObjects.Schema.IECClass},Bentley.EC.Persistence.Query.WhereCriteria,System.Object[])"> <summary>Private implementation method.Search all classes in query
We need public methods!
public
Regards, Jon Summers LA Solutions
Jon Summers said:We need public methods!
There is a public method and its description is available in XML file as well. Or do you think my code above does not work despite of I wrote it works, because used method is private? ;-)
And Visual Studio provides clarification one from overloaded methods is available: