I need to query from a CRM entity
some values where a linked entity
contains a string
inside its name
.
I try to explain:
- I have
new_supplycontract
table. - This table, has an
EntityReference
namednew_pod
- The
new_pod
entity, has two fields: new_citypod andnew_street
new_citypod
points to another entity namednew_city
new_street
points to another entity namednew_street
I need to query the new_supplycontract
table to retrieve only the records whose new_pod
contains a street
which name contains a string
I pass and a city
which name contains another string
i pass.
I know this code works for retrieving all new_supplycontract
entities whose two text fields "new_city
" and "new_address
" are like to two strings passed.
QueryExpression query = new QueryExpression(new_supplycontract.EntityLogicalName);
query.ColumnSet = new ColumnSet(true);
query.Criteria.AddCondition("new_city", ConditionOperator.NotNull);
query.Criteria.AddCondition("new_address", ConditionOperator.NotNull);
query.LinkEntities.Add(new LinkEntity(new_supplycontract.EntityLogicalName, "new_comune", "new_city", "new_comuneid", JoinOperator.Inner));
query.LinkEntities[0].Columns.AddColumns("new_name");
query.LinkEntities[0].EntityAlias = "comuneTemp";
query.LinkEntities[0].LinkCriteria.AddCondition("new_name", ConditionOperator.Like, "%" + comune + "%");
query.LinkEntities.Add(new LinkEntity(new_supplycontract.EntityLogicalName, new_via.EntityLogicalName, "new_address", "new_viaid", JoinOperator.Inner));
query.LinkEntities[1].Columns.AddColumns("new_name");
query.LinkEntities[1].EntityAlias = "viaTemp";
query.LinkEntities[1].LinkCriteria.AddCondition("new_name", ConditionOperator.Like, "%" + via + "%");
DataCollection<Entity> entities = service.RetrieveMultiple(query).Entities;
But I don't really know how to use this code for my goal. I don't know how to filter an entityreference's entityreference.
Any help will be appreciated