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.

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    May 17, 2010 @ 12:16
    Matt Brailsford
    0

    Selecting discounted products via LINQ?

    Hi Guys,

    I'm trying to do a LINQ query against EntitiesV2.Product to find all products which have a "Discount" property defined. I have the following statement:

     

     

    var products = Product.Find(x => x.ProductProperties.FirstOrDefault(y => y.ProductDefinitionField.Name == "Discount").Value != "").ToList();

    But am getting an exception:

    Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [.Where(.Select(NHibernate.Linq.NhQueryable`1[UCommerce.EntitiesV2.Product], Quote((entity) => (entity))), Quote((x) => (String.op_Inequality(.FirstOrDefault(.Where(x.ProductProperties, (y) => (String.op_Equality(y.ProductDefinitionField.Name, p1)))).Value, p2))))]

    Anybody got any ideas what this might be? And how I can do this query?

    Many thanks

    Matt

  • Søren Spelling Lund 1797 posts 2786 karma points
    May 17, 2010 @ 12:46
    Søren Spelling Lund
    0

    How about something like this

    var q = from prod in Product.All()
    join prop in ProductProperty.All() on prod.ProductId equals prop.ProductId
    join field in ProductDefinitionField.All() on prop.ProductDefinitionFieldId equals field.ProductDefinitionFieldId
    where field.Name == "Discount" && prop.Value == "My Brand" && prod.ParentProductId == null 
    select prod;

     

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    May 17, 2010 @ 12:57
    Matt Brailsford
    0

    I'm now getting:

    could not resolve property: ProductId of: UCommerce.EntitiesV2.ProductProperty [.Select(.Where(.Join(.Join(NHibernate.Linq.NhQueryable`1[UCommerce.EntitiesV2.Product], NHibernate.Linq.NhQueryable`1[UCommerce.EntitiesV2.ProductProperty], Quote((prod) => (prod.ProductId)), Quote((prop) => (prop.ProductId)), Quote((prod, prop) => (new <>f__AnonymousType0`2(prod, prop)))), NHibernate.Linq.NhQueryable`1[UCommerce.EntitiesV2.ProductDefinitionField], Quote((<>h__TransparentIdentifier0) => (<>h__TransparentIdentifier0.prop.ProductDefinitionFieldId)), Quote((field) => (field.ProductDefinitionFieldId)), Quote((<>h__TransparentIdentifier0, field) => (new <>f__AnonymousType1`2(<>h__TransparentIdentifier0, field)))), Quote((<>h__TransparentIdentifier1) => (AndAlso(AndAlso(String.op_Equality(<>h__TransparentIdentifier1.field.Name, p1), String.op_Inequality(<>h__TransparentIdentifier1.<>h__TransparentIdentifier0.prop.Value, p2)), Equal(<>h__TransparentIdentifier1.<>h__TransparentIdentifier0.prod.ParentProductId, p3))))), Quote((<>h__TransparentIdentifier1) => (<>h__TransparentIdentifier1.<>h__TransparentIdentifier0.prod)))]

  • Søren Spelling Lund 1797 posts 2786 karma points
    May 17, 2010 @ 13:15
    Søren Spelling Lund
    0

    The code was only tested for UCommerce.Entities.

    If you can you should hold off using V2 as there will be missing properties like the one you just found due to the fact that we're primarily using it for performance internally. Queries created against V1 and V2 will exhibit the same level of performance though.

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    May 17, 2010 @ 13:38
    Matt Brailsford
    0

    I switched to using V2 as I was (and having switched back to V1, still am) getting page load times of 5/7 seconds which are pretty much instant with V2.

    Does that mean I can't use V2 for this? as I have all other queries I need working with V2.

    Matt

  • Søren Spelling Lund 1797 posts 2786 karma points
    May 17, 2010 @ 13:58
    Søren Spelling Lund
    0

    I need to add support for your query. It's pretty straightforward though so I'll see if I can have a release ready for you later today.

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    May 17, 2010 @ 13:59
    Matt Brailsford
    0

    Cool, thanks Soren. I really appreciate it.

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft