Answered by:
FetchXML vs. QueryExpression

Question
-
Hi everybody,
As all you know with FetchXML we are able to retrieve different entity's different attributes in a single fetch with link entity. i.e: result xml could be 2 attribute from contact entity, 3 attribute from account entity and 6 entity from activity entity, but since it's returning xml which can be used as a dataset/datatable is useless for me, I need to get data as crm objects.
QueryExpression and LinkEntity is the correct answer which will return BusinessEntity typed data but here is the limitation: if you use QueryExpression /RetrieveMultiple it returns only one entity type like "contact" but I need to get other entities as well (account, activity) in same/singe query.
Can someone tell me, is there any way to do that ?Wednesday, January 13, 2010 8:23 AM
Answers
-
Hi
We have a C# library called XrmLinq, it automatically does this for you. Take a look here http://www.xrmlinq.comFor example:
var activities = (from t in _crm.Tasks
join account in _crm.Accounts on t.RegardingObjectId equals account.AccountId into aj
from a in aj.DefaultIfEmpty()
join contact in _crm.Contacts on t.RegardingObjectId equals contact.ContactId into cj
from c in cj.DefaultIfEmpty()
where t.RegardingObjectId == Guid.Empty
orderby t.CreatedOn descending
select new
{
t.Subject,
a.Name,
c.FullName
}).ToList();
The above is an example of what you can do with XrmLinq, it does a left outer join to accounts and contacts, gets all the tasks you specify for a uniqueidentifer (can be an account or a contact), orders by the newest task first and return an anonymous list.
As you can see it's all strongly typed, you don't need to know anything about FetchXml or QueryExpressions, it's all handled for you
XrmLinq - LINQ to Dynamics CRM http://www.xrmlinq.com - The smart way to query crm- Marked as answer by DavidJennawayMVP, Moderator Friday, February 19, 2010 5:59 PM
Wednesday, January 13, 2010 8:37 AM -
Query for the ids and make 3 seperate retrieve(multiple)s for the BusinessEntities.
No, you can't retrieve one thing and get 3 things.- Proposed as answer by mardukes Friday, January 15, 2010 5:09 PM
- Marked as answer by DavidJennawayMVP, Moderator Friday, February 19, 2010 5:59 PM
Wednesday, January 13, 2010 5:41 PM
All replies
-
Hi.
Way I see - you can convert entity from FetchXml result to DynamicEntities. But it seems to be complicated...
Truth is opened the prepared mind
My blog (english)
Мой блог (русскоязычный)Wednesday, January 13, 2010 8:29 AMModerator -
Hi
We have a C# library called XrmLinq, it automatically does this for you. Take a look here http://www.xrmlinq.comFor example:
var activities = (from t in _crm.Tasks
join account in _crm.Accounts on t.RegardingObjectId equals account.AccountId into aj
from a in aj.DefaultIfEmpty()
join contact in _crm.Contacts on t.RegardingObjectId equals contact.ContactId into cj
from c in cj.DefaultIfEmpty()
where t.RegardingObjectId == Guid.Empty
orderby t.CreatedOn descending
select new
{
t.Subject,
a.Name,
c.FullName
}).ToList();
The above is an example of what you can do with XrmLinq, it does a left outer join to accounts and contacts, gets all the tasks you specify for a uniqueidentifer (can be an account or a contact), orders by the newest task first and return an anonymous list.
As you can see it's all strongly typed, you don't need to know anything about FetchXml or QueryExpressions, it's all handled for you
XrmLinq - LINQ to Dynamics CRM http://www.xrmlinq.com - The smart way to query crm- Marked as answer by DavidJennawayMVP, Moderator Friday, February 19, 2010 5:59 PM
Wednesday, January 13, 2010 8:37 AM -
Hi,
You can convert Fetchxml to queryexpression and and vice-versa.
Check this Post
Hope it will help you !!!
MahainWednesday, January 13, 2010 8:42 AMModerator -
Hi,
You can convert Fetchxml to queryexpression and and vice-versa.
Check this Post
Hope it will help you !!!
Mahain
Truth is opened the prepared mind
My blog (english)
Мой блог (русскоязычный)Wednesday, January 13, 2010 8:44 AMModerator -
That won't help if you are linking entities and want to retrieve multiple attributes from those linked entities. QueryExpressions simply don't allow that.
XrmLinq - LINQ to Dynamics CRM http://www.xrmlinq.com - The smart way to query crmWednesday, January 13, 2010 8:46 AM -
Thanks for prompt reply.
Andriy: yes it'll be complicated with dynamics entity instead of business entity.
Amanda: since our application framework is 2.0, I can't use linq here but even if have chance to use linq; instead of buying licence I prefer to use LinqToCRM : http://linqtocrm.codeplex.com /Wednesday, January 13, 2010 8:51 AM -
Query for the ids and make 3 seperate retrieve(multiple)s for the BusinessEntities.
No, you can't retrieve one thing and get 3 things.- Proposed as answer by mardukes Friday, January 15, 2010 5:09 PM
- Marked as answer by DavidJennawayMVP, Moderator Friday, February 19, 2010 5:59 PM
Wednesday, January 13, 2010 5:41 PM