Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Feb 05, 2015 @ 11:55
    Søren Kottal
    0

    Get all products by custom property in array

    Hi all

     

    I'm trying to get all products in my catalog where the value of a custom property is in a predefined array.

     

     

    
        var eansstr = "4019238560824;4019238560825";
        var eans = eansstr.Split(';');
        var products = Product.All().Where(x => x.GetProperty("EAN").GetValue() == eans[0]);
        foreach (var p in products) {
    
    @p.Name
    }

     

    But I get the error message System.NotSupportedException: System.Object GetValue()

     

    How to fix?

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Feb 05, 2015 @ 12:46
    Søren Kottal
    101

    Took some advice from another thread and changed it to this:

     

    Product.All().Where(x => x.ProductProperties.Any(y => y.ProductDefinitionField.Name == "EAN" && eans.Contains(y.Value)));

     

    Now it works :)

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Feb 05, 2015 @ 12:51
    Nickolaj Lundgreen
    1

    Hi Søren

    The problem is that NHibernate can't translate "GetValue()" to SQL.

    The solution is quering from the productproperty entity like this:

    ProductProperty.All()
                .Where(pp => pp.ProductDefinitionField.Name == "EAN" && pp.Value == "ABC")
                .Select(pp => pp.Product);
    

    or like this

    Product.All().Where(p => p.ProductProperties.Any(pp => pp.ProductDefinitionField.Name == "EAN" && pp.Value == "abc"));
    

    (Not tested - hope it points you in the right direction)

Please Sign in or register to post replies

Write your reply to:

Draft