Possible problem with LINQ provider

Possible problem with LINQ provider

Old forum URL: forums.lhotka.net/forums/t/7911.aspx


Michael posted on Thursday, October 29, 2009

I have a Connection class which simply exposes two Guid properties, which are decorated with         [Indexable(IndexModeEnum.IndexModeAlways)]. In the Connections collection I have the following method:

public Connection GetConnection(Guid openingId)
{
    var data = from connection in this
               where connection.OpeningId1 == openingId
               select connection;

    if (data.Count() == 1)
        return data.First();

    data = from connection in this
           where connection.OpeningId2 == openingId
           select connection;

    return data.FirstOrDefault();
}


I'm doing two Linq queries to enable the index to work properly. (I can't do both checks in the same where, correct?) The method always returns null. When I change the condition to
where connection.OpeningId1.Equals(openingId) it works as expected.

Adding the generic extension method:

public static T Dump<T>(this T instance)
{
    Console.WriteLine(instance); return instance;
}


and changing the conditions to
where connection.OpeningIdX.Dump() == openingId.Dump() or where (connection.OpeningIdX == openingId).Dump() makes it work as expected also.

Why is it so?

Regards
Michael

AaronErickson replied on Friday, October 30, 2009

Hi Michael-

I suspect what is occuring is that the indexer test for equality does not go through an operator overload on == unless the type is primitive.  I have seen similar behavior before.  I suspect what I need to do is to check to see if == is supported and use that for checking equals.

I will likely put this on the backlog for updates in the .NET 4 version of CSLA, as there is a simple enough workaround for it.

Michael replied on Friday, October 30, 2009

Hi Aaron

Thanks for the reply. Does that really explain how the Dump() extension method fixes it, which simply returns the instance passed in?

AaronErickson replied on Friday, October 30, 2009

My guess is that using Dump probably moves it out of indexing mode... but it is hard to tell 100% without recreating a scenario.

Michael replied on Friday, October 30, 2009

That makes sense.

Copyright (c) Marimer LLC