Git Product home page Git Product logo

crmquery's Introduction

About

CrmQuery is a tiny domain-specific language for building queries against Microsoft Dynamics CRM. The structure is inspired by method-chaining libraries like jQuery and the syntax is inspired by plain SQL. CrmQuery wraps the QueryExpression interface and supporting classes, aiming at making queries easier to read and write.

#Synopsis

The following idiomatic example query traverses a parent-child tree relationships among instances of the same entity. In Sql this would be a self-join. In CRM it would be a LinkEntity that references the same entity type on either end. In this query we get all of the child nodes of the entity whose name is "hello":

QueryBase query = CrmQuery
    .Select()
    .From( "myentity" )
    .Join( "myentity", "parentid", "myentity", "myentityid" )
    .Where( "myentity", "name", ConditionOperator.Equal, new object[] { "hello" } )
.Query;

The corresponding Sql query would look like this:

select * from 
myentity e1
inner join myentity e2
on e1.parentid = e2.myentityid
where e1.name = 'hello'

Notice that the projection clause is assumed to be *, or in CRM parlance, AllColumns. Passing an instance of AllColumns to Select() will use the instance as the relational projection list.

In order to do the same thing using the raw CRM API you need quite a bit of code:

LinkEntity linkEntity = new LinkEntity();
		
linkEntity.LinkFromEntityName = "myentity";
linkEntity.LinkFromAttributeName = "parentid";
linkEntity.LinkToEntityName = "myentity";
linkEntity.LinkToAttributeName = "myentityid";
linkEntity.JoinOperator = JoinOperator.Inner;

QueryExpression query = new QueryExpression( "myentity" );
query.LinkEntities.Add( linkEntity );
query.ColumnSet = new AllColumns();
			
linkEntity.LinkCriteria.FilterOperator = LogicalOperator.And;
linkEntity.LinkCriteria.AddCondition( "name", ConditionOperator.Equal, "hello" );

The preceding code could be written using some convenience constructors but the structure of the query is still not apparent without looking closely at the code. Multiple criteria exacerbate the problem greatly.

#Status

CrmQuery is experimental software but is stable for many basic query types. Work is ongoing to improve the number of supported query constructs and increase test coverage.

#Limitations

CrmQuery only works with relatively simple queries. There is a slight impedance mismatch between a function-chaining interface and a set-based language like Sql. Subsequently, the order in which expressions are added can be important. CrmQuery tries to do the right thing by considering the last-added filter and also by walking up the tree of filters in order to find the correct filter to add a criteria to. This logic is crude and may not allow expression of some complex queries.

#License crmQuery is provided under the MIT software license. See the file LICENSE for the full text.

crmquery's People

Contributors

dnewcome avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.