Problem:
Working a dynamic linq issue. Using the great helper class, Predicate Builder posted over on the O'Reilly site. I had built out my query and it worked great against my EF generated class. Then I started getting this error each time I ran the predicate builder against a data type of nullable Guid. I searched around on line at some more in depth explanations. But nothing seemed to really fit my problem.
Solution:
Then I took the simple advice given on stackoverflow. I changed the following lines
var race = Guid.Parse(race_ID);
predicate = predicate.Or(l => l.Race_ID.Equals(race));
to
var race = Guid.Parse(race_ID);
predicate = predicate.Or(l => l.Race_ID==race);
C# interpreter at work here:
"When
so we could also do
var race = Guid.Parse(race_ID);
predicate = predicate.Or(l => l.Race_ID.Value.Equals(race));
==
is used on an expression of type object
, it'll resolve to System.Object.ReferenceEquals
.Equals
is just a virtual
method and behaves as such, so the overridden version will be used (which, for string
type compares the contents). "so we could also do
var race = Guid.Parse(race_ID);
predicate = predicate.Or(l => l.Race_ID.Value.Equals(race));
No comments:
Post a Comment