views:

44

answers:

2

I'm using the rules engine from WF in an application and some of the conditions involve searching a collection for a condition. It would be ideal to do something like:

this.CollectionObject.Select(x => x.WantedProperty == searchValue).Count() > 0

Unfortunately I don't seem to have access to the Linq extensions for collections. I've tried passing in System.Data.Linq through the TypeProvider param for RuleSetDialog but that didn't make the Linq methods show up.

Any help or ideas appreciated!

A: 

I've been able to get access to the extensions if I use the Query syntax instead of the Lambda syntax.

Ex: From x in CollectionObject select etc...

Edit: Added image

alt text

JSprang
I'm not able to use these in the RuleSetDialog. It won't recognize the syntax. Anything special you did to expose these?
GarthT
Sorry, maybe I don't understand exactly what the RuleSetDialog is, I'm not too familiar with Workflow. I've edited my post to show how I was able to perform a LINQ query and assign it to my object.
JSprang
A: 

Hi!

I don't have any experience with WF so my answer is only based on what I've seen on the web so far. You may want to check out this blog post.

The problem with Rule Set editor is that it doesn't allow the use of lambda expressions. They are still not first-class citizens in .NET dev tools world, e.g. Immediate window won't compile them either.

As far as I found out, there is no out-of-the-box solution to the problem, but this one looks fine to me:

Place all of your LINQ code style items in Properties or methods that you can then access from the Condition window. Not a superb answer, but it works in a bind.

You may want to define a property like

public bool HasAnyBeatlesAlbums {
    get {
        return this.MusicLibrary.Any (cd => cd.Artist == "Beatles");
    }
}

and then use this property in your set expression. I also would like to note that using Any extension method is preferred for finding out if a sequence is not empty because Any doesn't require all elements to be enumerated.

Please let me know it it works for you.

gaearon
I may end up using this solution if I can't come up with something more generic. I tried doing this with generics to no avail thus far. The requirement is that this should be configurable through some sort of interface or text file.... That requirement might have to be fudged - at least in the short term.
GarthT