Giter Site home page Giter Site logo

redgoldenfish / mscrmtools.fluentqueryexpressions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mscrmtools/mscrmtools.fluentqueryexpressions

0.0 0.0 0.0 111 KB

A library to create QueryExpression the fluent way

License: GNU General Public License v3.0

C# 100.00%

mscrmtools.fluentqueryexpressions's Introduction

MscrmTools.FluentQueryExpressions

A library to create QueryExpression the fluent way

Build status

You can rely on :

Query properties

var query = new Query<Account>()
                .Top(10)
                .Distinct()
                .NoLock()
                .SetPaging(1, 100, true);                
                

Selecting fields

var earlyBoundQuery = new Query<Account>()
                .Select(Account.Fields.Name, Account.Fields.AccountNumber);
                
var earlyBoundQuery2 = new Query<Account>()
                .Select(a => new { a.Name, a.AccountNumber});
                
var lateBoundQuery = new Query("account")
                .Select("name", "accountnumber");
                

Adding conditions

var earlyBoundQuery = new Query<Account>()
                .Select(Account.Fields.Name, Account.Fields.AccountNumber)
                .WhereEqual(Account.Address1_City, "Paris");
                
var lateBoundQuery = new Query("account")
                .Select("name", "accountnumber")
                .WhereEqual("address1_city", "Paris");
                

Adding filters

var earlyBoundQuery = new Query<Account>()
                .Select(Account.Fields.Name, Account.Fields.AccountNumber)
                .AddFilters(new Filter(LogicalOperator.Or)
                    .WhereEqual(Account.Address1_City, "Paris")
                    .WhereEqual(Account.Address1_City, "Nantes")
                );
                
                
var lateBoundQuery = new Query("account")
                .Select("name", "accountnumber")
                .AddFilters(new Filter(LogicalOperator.Or)
                    .WhereEqual("address1_city", "Paris")
                    .WhereEqual("address1_city", "Nantes")
                );
                

Comparing Columns (online only, from 2020 July 1st)

var earlyBoundQuery = new Query<Account>()
    .Select(Account.Fields.Name, Account.Fields.AccountNumber)
    .Compare(Account.Fields.CreatedOn).LessThan(Account.Fields.ModifiedOn);

var lateBoundQuery = new Query("account")
    .Select("name", "accountnumber")
    .Compare("createdon").LessThan("modifiedon");

Adding link entity

var earlyBoundQuery = new Query<Account>()
                .Select(Account.Fields.Name, Account.Fields.AccountNumber)
                .AddLink(new Link<Contact>(Contact.Fields.ParentCustomerId, Account.Fields.AccountId, JoinOperator.LeftOuter)
                    .SetAlias("cont")
                    .Select(Contact.Fields.Fullname)
                    .WhereEqual(Contact.Address1_City, "Paris")
                    .WhereEqual(Contact.Address1_City, "Nantes")
                );
                
                
var lateBoundQuery = new Query("account")
                .Select("name", "accountnumber")
                 .AddLink(new Link(Contact.EntityLogicalName, Contact.Fields.ParentCustomerId, Account.Fields.AccountId, JoinOperator.LeftOuter)
                    .SetAlias("cont")
                    .Select("fullname")
                    .WhereEqual("address1_city", "Paris")
                    .WhereEqual("address1_city", "Nantes")
                );
                

Adding order

var earlyBoundQuery = new Query<Account>()
                .Select(Account.Fields.Name, Account.Fields.AccountNumber)
                .Order(Account.Fields.Name, OrderType.Ascending);
                
                
var lateBoundQuery = new Query("account")
                .Select("name", "accountnumber")
                .Order("name", OrderType.Ascending);
                

Executing query

Either retrieve QueryExpression property or use one of the method to get records

var qe = new Query("account").QueryExpression;

List<Account> records = new Query<Account>().GetAll(iOrganizationService);
Account record = new Query<Account>().GetFirst(iOrganizationService);
Account record = new Query<Account>().GetFirstOrDefault(iOrganizationService);
Account record = new Query<Account>().GetLast(iOrganizationService);
Account record = new Query<Account>().GetLastOrDefault(iOrganizationService);
Account record = new Query<Account>().GetSingle(iOrganizationService);
Account record = new Query<Account>().GetSingleOrDefault(iOrganizationService);
EntityCollection records = new Query<Account>().GetRecords(iOrganizationService);

mscrmtools.fluentqueryexpressions's People

Contributors

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