var remainingProductsInCollection = @Model.Parent.Children.Where("Name.ContainsAny(productCodes)", valuesForFilter);
The reverse case, no ! before "Name" Also can you try on a non default property, i.e. a property added to the doc type. It sounds like the expression tree is missing a couple of if statements when dealing with the lambda (this is something for me to fix, but I am trying to get some more accurate debugging info about what cases it fails with and which ones it works with)
unfortunately that does not work.. hmm.. if I try it on a non default property i get sequence contains no matching element as an exception.. but that looks like it's kicking it in to gear..
is there a workaround for this kind of functionality I could use for now..
In Extension Method Finder Line 130: firstMethod = methods.First(x => x.IsGenericMethodDefinition); that is where it is blowing up if I try on a non default
Okay, that's progress though, it suggests there's two bugs with ContainsAny
The workaround would be to write a class library with your static extension method you want accessible with the reverse of ContainsAny (e.g. NotContainsAny), I think that was documented in part 3 as well, but referenced in part 5.
I am not sure what's throwing the sequence contains no matching element.
The other possible workaround would be a longhand where, for example:
.Where("Name != "blah" && Name != "blah2") but you'd need to know the values
Or just have a standard contains check as an if statement inside your loop (messy but a workaround always is)
In Extension Method Finder Line 130: firstMethod = methods.First(x => x.IsGenericMethodDefinition); that is where it is blowing up if I try on a non default
That suggests that "methods" didn't find any methods by that name.. odd.
I'll change that First to be FirstOrDefault and null check for the 4.7.1 beta
hmm might have to write an extension method and see how I go.. please keep me posted on this as it's a really awesome feature.. ill get one of the guys to have a look here with me this morning to see if we can track down what it's doing..
I wonder if I could take one of your contains any methods from the source code and move it into an extension..
I am running two 4.7.0 sites where i've just "half upgraded" (by replacing the binaries) the site to 4.7.1 to test razor features. A few things are probably broken as the aspx/ascx/asmx/css/js etc files should also be updated. I don't recommend this for a production site, This build is current as of 2011-07-22 and I will periodically update it http://dl.dropbox.com/u/2923715/LatestRazorMacroEngine.zip
No applicable method 'ContainsAny' exists in type 'String
I was just wondering in this instance why the extension method wasn't being picked up.. and for now is there a workaround:
No applicable method 'ContainsAny' exists in type 'String
when trying to do the filter on @Model.Parent.Children in the line below where I'm setting the var: remainingProductsInCollection..
Is anyone aware of a way to work around this?
var valuesForFilter = new Dictionary<string, object>();
var productCodes = new List<string>();
foreach (var selectedProduct in recommendedProducts)
{
productCodes.Add(selectedProduct.Name);
}
if (productCodes.Count > 0)
{
valuesForFilter.Add("productCodes", productCodes);
var remainingProductsInCollection = @Model.Parent.Children.Where("!Name.ContainsAny(productCodes)", valuesForFilter);
if (remainingProductsInCollection != null && remainingProductsInCollection.Items.Count > 0)
{
var remainingProductsToAdd = remainingProductsInCollection.Items.Count > recommendedProductsCount ? remainingProductsInCollection.Items.Random(recommendedProductsCount) : remainingProductsInCollection.Items;
recommendedProducts.AddRange(remainingProductsToAdd);
}
}
Does *this* work:
var remainingProductsInCollection = @Model.Parent.Children.Where("Name.ContainsAny(productCodes)", valuesForFilter);
The reverse case, no ! before "Name"
Also can you try on a non default property, i.e. a property added to the doc type.
It sounds like the expression tree is missing a couple of if statements when dealing with the lambda (this is something for me to fix, but I am trying to get some more accurate debugging info about what cases it fails with and which ones it works with)
Hi Gareth,
unfortunately that does not work.. hmm.. if I try it on a non default property i get sequence contains no matching element as an exception.. but that looks like it's kicking it in to gear..
is there a workaround for this kind of functionality I could use for now..
In Extension Method Finder Line 130: firstMethod = methods.First(x => x.IsGenericMethodDefinition); that is where it is blowing up if I try on a non default
Okay, that's progress though, it suggests there's two bugs with ContainsAny
The workaround would be to write a class library with your static extension method you want accessible with the reverse of ContainsAny (e.g. NotContainsAny), I think that was documented in part 3 as well, but referenced in part 5.
I am not sure what's throwing the sequence contains no matching element.
The other possible workaround would be a longhand where, for example:
.Where("Name != "blah" && Name != "blah2") but you'd need to know the values
Or just have a standard contains check as an if statement inside your loop (messy but a workaround always is)
Gareth
Re:
In Extension Method Finder Line 130: firstMethod = methods.First(x => x.IsGenericMethodDefinition); that is where it is blowing up if I try on a non default
That suggests that "methods" didn't find any methods by that name.. odd.
I'll change that First to be FirstOrDefault and null check for the 4.7.1 beta
Cheers Gareth,
hmm might have to write an extension method and see how I go.. please keep me posted on this as it's a really awesome feature.. ill get one of the guys to have a look here with me this morning to see if we can track down what it's doing..
I wonder if I could take one of your contains any methods from the source code and move it into an extension..
Hi Guys,
Just thought I'd post a workaround for you
At Gareth's suggestion I made an extension method.. with an overload.. so!
public static DynamicNodeList NotContainsAny(this DynamicNodeList all, List<string> valuesForComparison)
{
var items = all.Items.Where(item => !valuesForComparison.Contains(item.Name));
return new DynamicNodeList(items);
}
public static DynamicNodeList NotContainsAny(this DynamicNodeList all, string propertyName, List<string> valuesForComparison)
{
var items = all.Items
.Where(
item =>
{
var property = item.GetProperty(propertyName);
return (property != null) && !valuesForComparison.Contains(property.Value);
}
);
return new DynamicNodeList(items);
}
Awesome Tom,
By the way, does anyone else actually use this feature ;)
Gareth
haha :)
Fixed in 4.7.1
Thanks that'd be great I'll try the binary.. but im running 4.7.0..
Cheers,
Tom
I am running two 4.7.0 sites where i've just "half upgraded" (by replacing the binaries) the site to 4.7.1 to test razor features.
A few things are probably broken as the aspx/ascx/asmx/css/js etc files should also be updated.
I don't recommend this for a production site,
This build is current as of 2011-07-22 and I will periodically update it
http://dl.dropbox.com/u/2923715/LatestRazorMacroEngine.zip
Gareth
@Gareth Evans
FYI, I use "ContainsAny" in Razor C# and I think it is really nice to have this feature working.
Thus, thank you Gareth Evans for your help fixing/patching the "ContainsAny", I will test your patch. Much appreciated. :)
I already posted the same issue weeks ago:
http://our.umbraco.org/forum/developers/razor/19767-Trying-to-use-containsAny-in-Razor-in-47
is working on a reply...