none
automatic(??) capitalization of field names in objects create from LINQ query RRS feed

  • Question


  • I have a situation where compiling on my machine, I get a different behavior than my coworkers and production builds.

    Execution of the following in debugger,

    test = From bpt In CustomBProcessTypes Select text = bpt.Name(), value = bpt.Id

    and look at test with quickwatch, expand to look at the elements, and the fields of the elements are 'text' and 'value'.  Yet when my coworker did the same, the field names were 'Text' and 'Value'.  Note the difference in capitalization, and note that the fields are uncapitalized in the query.

    One coworker suggested delete my .suo file for the project (I renamed it).  At first this did not affect the behavior, but then after I made an unrelated change to the source code that cause the project to rebuild next time I ran it in debugger, mine started capitalizing the field names.  Oddly enough restoring the previous .suo file and or undoing the source code change was not enough to bring back the non-capitalizing behavior.

    It appears though that there is something that configures LINQ to automatically capitalize field names of generic objects created from queries, and somehow I did not have this configured in my environment, and somehow deleting the .suo file changed my environment such that LINQ started capitalizing the field names.

    I've tried googling and searching for anything related to this to no avail.

    Any idea what is going on?  Is there some environment/build configuration option for LINQ that controls this (and where would I find that?  Maybe somehow my environment was referencing an older version of LINQ with different behavior?  What would deleting the .suo file have to do with it?

    Tuesday, January 14, 2014 10:53 PM

All replies

  • Hello,

    >>  Is there some environment/build configuration option for LINQ that controls this (and where would I find that?

    Do you mean that you see the “text” and “value” as below if you use linq query?

    Dim result = (From order In db.Orders
    
                                  Select text = order.OrderCode, value = order.OrderName)

    This should be normal. It should be that if you write the text to be lowercase, then we see it to be lowercase. And there is no some environment/build configuration option for LINQ for the capitalize behavior.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, January 16, 2014 5:29 AM
    Moderator
  • No and Yes.

    "Yes" in that I am seeing the "normal" behavior, on my machine.  "No" because the capitailisation so the field names are "Text" and "Value" are occurring on my coworkers machines and in our production builds.

    Stranger still, since I posted this, the behavior has switched back and forth in my environment, for no identifiable reason.  I thought I had "fixed" it by deleting the .suo file, after which, I could verify in quickwatch that I was getting field names "Text" and "Value" (which is the "incorrect" behavior for linq, but which hs been the "correct" behavior in our production build for a very long time, near as I can tell).  But after moving on and working on other code changes (I'm quite sure are unrelated) for a few hours a later build hung up on the same "problem" -- it started naming the fields "text" and "value" again.

    I originally found this discrepancy because I was getting an error in my debug build tht was not occurring in production build -- because mine was *not* capitalizing "text" and "value" field names, a subsequent reflection getfield("Text") (or getproperty("Text")) would fail (same for "Value") -- causes the application to hang at a specific point, which does not happen in otherwise identical production build, also does not happen on coworker's debug build.

    Please note, I am stepping carefully through the code and, examining using quickwatch, exactly as you have shown above.  This is really happening.  Consistently on coworkers' machines, they get capitalized "Text" and "Value" fields where they are lowercase in that query, but (most of the time) I do not get them capitalized.  At least for this particular query.  I have created a toy project and do not get auto-capitalization for a similar query.  The same toy project on my coworker's machine also did not capitalize the field names.

    This is of course easy to "fix" -- I can explicitly capitalize the field names in the query and/or make the calls to getfield/getproperty case-insensitive with optional binding flags parameter.

    But it bothers me greatly that our production code has been relying on what may well be a bug in LINQ.  In fact it appears that the calls such as getfield("Text") were a prior developer's response to this auto-capitalization of the field names.

    Thursday, January 16, 2014 4:27 PM
  • Since we cannot reproduce the issue, we have submit this issue to:

    https://connect.microsoft.com/VisualStudio/feedback/details/813980/strange-behavior-in-linq-query-found-in-quickwatch-windows

    If they have any result, we will tell you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 17, 2014 10:04 AM
    Moderator
  • Thanks for the help.  I will be interested to see if they find anything.
    Friday, January 17, 2014 5:05 PM