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.

  • Neo 22 posts 42 karma points
    Apr 20, 2011 @ 14:57
    Neo
    0

    Entities V2 - Linq issue

    Hi Guys

     

    My requirement is to get the category name from the product sku. 

     

    This is my query and I'm using Entities V2

     

    var query = from rel in CategoryProductRelation.All()

    join prod in Product.All() on rel.ProductId equals prod.ProductId

    join categ in Category.All() on rel.CategoryId equals categ.CategoryId

    where prod.Sku == _sku && prod.VariantSku == null

    select categ;

     

    return (query.SingleOrDefault().Name);

     

    while executing the query i'm getting this error:

    System.Linq.IQueryable`1[UCommerce.EntitiesV2.Category] Where[Category](System.Linq.IQueryable`1[UCommerce.EntitiesV2.Category], System.Linq.Expressions.Expression`1[System.Func`2[UCommerce.EntitiesV2.Category,System.Boolean]]) 

     

    and the query is working perfectly for uCommerce.Entities

    Any thoughts on this?

    Neo

  • Søren Spelling Lund 1797 posts 2786 karma points
    Apr 21, 2011 @ 13:37
    Søren Spelling Lund
    0

    Hi Neo,

    Try query.ToList().SingleOrDefault().

  • Neo 22 posts 42 karma points
    Apr 22, 2011 @ 07:31
    Neo
    0

    Sorry Soren. Its not working but I have found a workaround for this issue. By using the following query its working properly (remove the line "join categ in Category.All() on rel.CategoryId equals categ.CategoryId" and select rel)

     

    var query = from rel in CategoryProductRelation.All()

    join prod in Product.All() on rel.ProductId equals prod.ProductId

    where prod.Sku == _sku && prod.VariantSku == null

    select rel;

    return (query.SingleOrDefault().Category.Name);


    Category is already populated with the above query. 

     

    Is there any reason for this?

     

    Regards
    Neo

  • Søren Spelling Lund 1797 posts 2786 karma points
    Apr 22, 2011 @ 10:37
    Søren Spelling Lund
    0

    I suspect the ORM mappings are to blame. I will recreate on my end and come up with a fix.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Apr 26, 2011 @ 14:29
    Søren Spelling Lund
    0

    I dug deeper and it works if you swap relation and category in your join it works as expected. I'm inclined to chalk this up to a finicky LINQ provider. I upgraded to NHibernate 3.1 for good measure but it exhibits the same behavior.

Please Sign in or register to post replies

Write your reply to:

Draft