Recently I am having a problem in converting an sql query to linq against EF in vb.net win forms 4.0
See my previous post for the particular query, so i posted the question to SO in which i got response in form of a link further with the help of that particular link i was able to find another link in asp.net forum using that i am able to find arrive the expected output in linq .
So Everything is fine at last, but the answer contained in the referred link for my question in stack overflow contains a keyword “KEY” while grouping the EF table. And that throws me compile time error in vb.net, so i have to search for that and find the answer in the asp.net forum which omits the “KEY” keyword. Essentially i just want to find out what happened to the referred answer and answer i got. So i just did a search in MSDN which strangely shows lot links from SO site itself. Actually i can say that the results are much more better than the Google result (strange). And out the links this one was exactly reflects my question. The accepted answer is also the answer which i have found from other links. But oddly enough this , this and this links are raising the same question which i have got in mind when working through the solutions. And the only man who answered all the three question is Jon Skeet , It seems that the key keyword is mutable in vb.net and by default it is immutable in C#
In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created.[1] This is in contrast to a mutable object, which can be modified after it is created. In some cases, an object is considered immutable even if some internally used attributes change but the object’s state appears to be unchanging from an external point of view. For example, an object that uses memoization to cache the results of expensive computations could still be considered an immutable object.
Immutable objects are often useful because they are inherently thread-safe.[1] Other benefits are that they are simpler to understand and reason about and offer higher security than mutable objects.[1]
The above mentioned paragraph is taken from wikipedia which obviously states the difference between mutable and immutable objects.
so to my understanding when you are creating an anonymous type in c# the the variable which is holding the output is immutable i.e. you don’t have to declare the key keyword , but in vb.net you have to make the object immutable explicitly .
from what i understand from this msdn link if you are declaring an anonymous type you should consider using KEY , which can be correlated to the primary key of sql database so that you can compare or get Hashcode values , if there is no key is declared while using anonymous type you cannot compare , get max value or group or Distinct effectively ,simply they wont give you any proper results.
so how to get the key to be displayed while grouping your vb.net anonymous type
that’s i am yet to find. (to be continued…)