I’ve asked a similar question before here and the answer solved my problem. However, now I’m getting the same problem as before but the answer doesn’t work anymore due to change in conditions.
Here’s the query I’m running. I’ve checked that someField is set to something (it’s a look-up field referring to an other entity by a guid). I get no entries in result (unless I switch the condition to “not equal”). That’s probably due to the fact that the field isn’t brought in.
When i breakpoint the execution and check Attributes, I see 21 fields out of a total of 30 (some of them might be empty, sure, but this one, i.e. someField, is not) but the one I’m interested in, isn’t there!
QueryExpression query = new QueryExpression
{
EntityName = "entity",
ColumnSet = new ColumnSet{ AllColumns = true },
// Here I tried the code addition #1 below
Criteria =
{
Filters =
{
new FilterExpression
{
Conditions =
{
new ConditionExpression("someField", ConditionOperator.Equal, guid)
}
}
}
}
};
// Here I tried the code addition #2 below
EntityCollection result = Service.RetrieveMultiple(query);
What do I miss and how can I resolve it?
I tried using LinkEntities as discussed in this blog but it didn’t really work out. I’m not even sure if it was a meaningful approach. It looked as follows.
LinkEntities =
{
new LinkEntity
{
Columns = new ColumnSet { AllColumns = true },
LinkFromEntityName = "entity",
LinkFromAttributeName = "otherEntityId",
LinkToEntityName = "entity2",
LinkToAttributeName = "entity2Id"
}
},
I also tried to employ the solution suggested on MSDN. The same result.
request.LinkEntities.Add(
new LinkEntity(
"entity", "entity2", "otherEntityId", "entity2Id", JoinOperator.Inner));
request.LinkEntities[0].Columns.AddColumns("entity2Id");
request.LinkEntities[0].EntityAlias = "blobb";
Once again – the solution provided by @JamesWood isn’t working anymore, since I’ve got the administrator access and the regarded field is not empty.
I believe the issue here is in your
FilterExpressionand/or the actual data itself.From what you have said here:
When you set the filter to “equal”, nothing is equal to that Guid so you get no results.
When you set the filter to “not equal”, everything is not equal to that condition so you start getting some results. When you do get results the lookup is not included because it is null the record (and hence why the “equal” filter doesn’t work).
As I’m not certain about the exact issue I suggest taking these steps:
AllColumns = true) without specifying aFilterExpression.FilterExpression.There is an example of filtering with a lookup here.
As a side note; you don’t actually have to specify in the
ColumnSetcolumns you are going to use for filtering.E.g. in SQL you could do: