[CONNECT .NET] ECQuery

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.

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...

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?

Parents
  • 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:

    • EC schema ("DgnCustomItemTypes_MasterPlanner__x0020__")
    • EC class (or classes) you want to search ("Something")
    • EC property in the classes ("ID")
    • An evaluation criteria, which is "ID is equal to 1" in this case.

    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 :-))))

  • 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!

     
    Regards, Jon Summers
    LA Solutions

Reply Children