0

I'm building the following query. For some reason, it doesn't bring to me all the fields. I've checked the spelling and when I assign values to those field, I even switched the name, leading to an exception. So I know for sure that they exist and are used. I'm adding a pre-image to the update-step with all data, just to be sure.

QueryExpression request = new QueryExpression
{
  EntityName = "myLogicalName",
  ColumnSet = new ColumnSet { AllColumns = true },
  Criteria =
  {
    Filters =
    {
      new FilterExpression
      {
        FilterOperator = LogicalOperator.Or,
        Conditions =
        {
          new ConditionExpression("someField", ConditionOperator.NotEqual, someValue),
          new ConditionExpression("someField", ConditionOperator.Equal, somValue)
        }
      }
    }
  }
};

EntityCollection result = Service.RetrieveMultiple(request);

What can I be possibly missing?!

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • What do you mean "doesn't bring me all the fields" – Daryl Oct 26 '12 at 13:16
  • @Daryl The instance of `ColumnSet` doesn't contain columns corresponding to **all** the fields in the custom entity. One would expect that requesting "all columns" would give one all the columns known to that entity. As of now, it feels like this. "List all the countries." "OK, Sweden, USA, Tuvalu. Done!" – Konrad Viltersten Oct 26 '12 at 13:18
  • So your expecting ColumnSet to automagically contain all the columns for your "myLogicalName" entity when you set the AllColumns property to true? – Daryl Oct 26 '12 at 13:21
  • @Daryl Yes, more or less. After all, I'm providing a reference to the appropriate table in SQL DB via logical name. It's not exactly rocket science to check what columns are defined in there (I'm simplifying, of course, a bit). By what you wrote, I read that I shouldn't... Why? – Konrad Viltersten Oct 26 '12 at 13:42

2 Answers2

3

Its probably because; the field does not have a value or field level security is being applied.

As a side generally you should avoid using AllColumns = true

James Wood
  • 17,286
  • 4
  • 46
  • 89
  • I know, i know. In the real version I have `new ColumnSet("donkey")` but here, I wanted to show that **all** the columns are included. And you're (at least) partially correct - the field we're talking about **is** empty, although I'm assigning it a value on "create"-message. Very unexpected behavior of "all columns" (meaning "only those that have value"). Now, **why** it's empty still (no exception while assigning it), is a mystery to me. – Konrad Viltersten Oct 26 '12 at 03:55
  • Ah, there it was. If they are dirty, they're in the context from page. Otherwise, I need to obtain them from an image. I need to cover **both** cases. This was a really sneaky gotcha. Thanks! – Konrad Viltersten Oct 26 '12 at 17:37
1

Setting the AllColumns property to true is essentially the same as doing a Select * in sql. The columns won't be adding to the ColumnSet, but they will be returned in the results of your query expression.

Daryl
  • 18,592
  • 9
  • 78
  • 145
  • No, it's not. If it would be essentially the same thing, they **should** be in the `ColumnSet`. I only have access to filled fields **and** those that have an updated value. It wasn't very straightforward to get the data - I got a lot of crashes, instead. – Konrad Viltersten Oct 26 '12 at 17:39
  • @Chamster Setting the AllColumns Property to true does nothing on the client side as far as actually adding the columns to the collection. But when your query expression is deserialized on the server, then the "select *" is performed, and your columns are returned. – Daryl Oct 26 '12 at 20:25
  • I'm starting to see it now. Dynamics CRM can be a bit confusing sometimes, hehe. Thanks. – Konrad Viltersten Oct 26 '12 at 20:44
  • Would you kindly give me a suggestion how to include values from certain columns? I've made sure they are populated now but still don't get them in. I've posted a new question on that subject [here](http://stackoverflow.com/questions/13103218/how-to-get-all-populated-columns-from-crm-using-queryexpression-object). – Konrad Viltersten Oct 27 '12 at 19:10