[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 Reply
  • Hi Jon,

    Does it perform more efficient selection and sorting than using LINQ after  GetInstances?

    I do not know how exactly ECQuery is implemented (but a study of ECquery assemblies code provides some insight and ideas), but I think LINQ will be far slower ... because LINQ is always slow (especially when there is no knowledge how LINQ works internally and queries are not implemented in a right way and cannot be optimized internally) Slight smile

    My assumption is:

    When ECQuery with criteria is used, formalized query is passed to native API and processed very close to DGN data. It means the search is fast and only limited amount of data is returned back to native API.

    When LINQ is used to posprocess, evaluate and filter results from ECQuery, possible all data have to be passed (and marshalled) to managed API and even when optimizations like lazy instantiation (known from e.g. Entity Framework) will be used, to evaluate conditions and filter elements, the elements (and EC classes and any other data) have to be instantiated in NET (memory intensive) or marshalled from native to managed (processor intensive).

    With regards,

      Jan

Children