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.
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.
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
Hi Neo,
Try query.ToList().SingleOrDefault().
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
I suspect the ORM mappings are to blame. I will recreate on my end and come up with a fix.
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.
is working on a reply...