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?