Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

FluentAPI for CRM's FetchXML

(0) ShareShare
ReportReport
Posted on by

What's about FluentAPI for CRM's FetchXML ?

xml construction by concatenating strings together, can be a real pain


I'm newbie with CRM, and now I have discovered a great component Fluent, I guest, not tested yet.

For me, it's great using Fluent and not more large big strings Fetch XML (great pain)


Is the component valid for this large string Fetch XML?

Using 2 link-entity nested with filter?

Full Fetch XML in http://pastebin.com/BrvwNWDv

And attributes with alias as


< attribute name='rsg_codigodeaire' alias='new_codigocampaaaire'/>


Sample:

IOrganizationService organisationService = null; // CreateCrmService();

// construct FetchXml using fluent-api
FetchQuery query = new FetchQuery("lead")
    .Filter(f => f.Gt("budgetamount", 5000))
    .Attributes("fullname", "companyname", "budgetamount");

// execution requires only one single line
IReadOnlyList<Entity> result = query.RetrieveMultiple(organisationService);

foreach(Entity entity in result)
{
    Console.WriteLine($"{entity["fullname"]}: {entity["budgetamount"]}");
}

https://github.com/tofi9/MSCRM-FetchXml/issues/1

I nuget must haves about CRM
http://nugetmusthaves.com/Tag/CRM?page=5
CRM-Fluent-Extension but not for Fetch XML
http://amoedo.github.io/CRM-Fluent-Extension/

And for more complex Fetch XML:

     var query = new FetchQuery("contact")
                .Attributes("firstname", "lastname", "fullname")
                .Filter(f => f
                    .SubFilterOr(f2 => f2
                        .SubFilterAnd(f3 => f3
                            .Eq("firstname", "Sam")
                            .Eq("lastname", "Jones"))
                        .SubFilterAnd(f3 => f3
                            .Like("lastname", "%(sample)%"))))
                .AllAttributes();

            var fetchxml = query.ToString();

            Assert.AreEqual(@"<?xml version=""1.0"" encoding=""utf-16""?>
<fetch xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
  <entity name=""contact"">
    <filter>
      <filter type=""or"">
        <filter>
          <condition attribute=""firstname"" operator=""eq"" value=""Sam"" />
          <condition attribute=""lastname"" operator=""eq"" value=""Jones"" />
        </filter>
        <filter>
          <condition attribute=""lastname"" operator=""like"" value=""%(sample)%"" />
        </filter>
      </filter>
    </filter>
    <attribute name=""firstname"" />
    <attribute name=""lastname"" />
    <attribute name=""fullname"" />
    <all-attributes />
  </entity>
</fetch>", fetchxml);



Any suggestions, what is your (experienced) opinions about it?

*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans