This is a migrated thread and some comments may be shown as answers.

Object reference error while executing query

1 Answer 38 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 2
Erik asked on 10 Oct 2012, 01:07 PM
Hi all,

The code snippet below always results in an object reference error and I can'f figure out why.

IQueryable<Product> categoryProducts = currentCategory.ProductsInChildCategories;
 
var products = (from p in categoryProducts
         join cp in context.CustomerPrices on p.ProductId equals cp.ProductId
        where p.LockedSince.Equals(null)
         && (customerIdForPrices <= 0 || cp.CustomerId == customerIdForPrices)
         && cp.MinimumQuantity == 0
         && (manufacturerId <= 0 || p.ManufacturerId == manufacturerId)
         && (!HideCombinationProducts || !p.IsCombination)
         && (eANCode == String.Empty || p.EANCode.Contains(eANCode))
         && (onStock <= 0 || p.OnStock > 0)
         select new
         {
             ProductId = p.ProductId,
             Name = p.Name,
             Description = p.Description,
             ActionPrice = cp.ActionPrice,
             Price = cp.Price,
         });

If I change the code so that I query an OpenAccess context like 'from p in context.Products', it works perfectly.
Any idea what's going wrong?

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 12 Oct 2012, 01:44 PM
Hello Erik,

Can you please provide us with some more details about the currentCategory instance? What is its type and where does it come from - is it an OpenAccess persistent object?  Please also share the implementation of the ProductsInChildCategories property. By default OpenAccess does not generate properties of type IQueryable<T>, so if you have added this property manually, the problem could be that the actual type of this collection cannot be cast to IQueryable<T>, therefore the property returns null.

Kind regards,
Alexander
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Tags
General Discussions
Asked by
Erik
Top achievements
Rank 2
Answers by
Alexander
Telerik team
Share this question
or