Object reference error while executing query

2 posts, 0 answers
  1. Erik
    Erik avatar
    9 posts
    Member since:
    Jul 2012

    Posted 10 Oct 2012 Link to this post

    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?
  2. Alexander
    Alexander avatar
    727 posts

    Posted 12 Oct 2012 Link to this post

    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,
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
  3. DevCraft banner
Back to Top