CSLA Linq Provider

CSLA Linq Provider

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


acgritt posted on Wednesday, December 23, 2009

I have found several times that using LINQ against the CSLA Business Objects have generated some unexpected results.  These have usually been easy to get around by inserting a .ToList() call in the chain of Linq statements.  However, is there an easy way to disable the CSLA Linq Provider without removing it from the codebase?

The most recent issue I found was when I had a call similar to this:

Channels.Where(chan => chan.OtherChannelReference == Id).OfType<Csla.Core.BusinessBase>()

If the Channels list has 4 items in it, this query will always return the 4 items because the Where clause seems to be skipped and only the OfType seems to be run.  If I do the following:

Channels.SelectMany(chan => chan.ChildList.Where( cl => cl.ChannelReference == Id)).OfType<>()

Then the call works fine.

RockfordLhotka replied on Wednesday, December 23, 2009

There is no way to disable the L2C behavior, no.

In CSLA .NET 4.0 the LINQ support will undergo radical change, which should resolve this issue.

The change is that you'll need to explicitly opt in to get a synchronized result list, and by default you'll only get LINQ to Object behaviors.

I'm sure this will make some people happy because things like you are doing should work as normal.

Of course I'm also sure it will make a lot of people unhappy as they bind to LINQ resuts and find that items they add/delete in the collection aren't really added/deleted in the database - until they find out they needed to use the .ToSynchronizedList() extension method (or whatever we call it).

This is clearly a no-win situation though, so I'm switching the CSLA implementation to the option that requires the least work for me :)

Copyright (c) Marimer LLC