开发者

Is there a way to use lambda expressions in a RuleSetDialog to define a condition?

开发者 https://www.devze.com 2023-01-18 10:47 出处:网络
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:

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.WantedPropert开发者_运维技巧y == 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!


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.


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

Is there a way to use lambda expressions in a RuleSetDialog to define a condition?

0

精彩评论

暂无评论...
验证码 换一张
取 消