0

Let me preface this by saying I'm a novice with LINQ, and that this is code that I didn't originally write but am trying to fix. I've done a lot of research on this error, but I haven't found anything helpful yet. In fact, this error sort of makes my head spin. Anyway...

I have a LINQ query that is selecting some data from three SharePoint lists. Here it is:

    private void loadPEGrid(int id)
    {
        dc = new SpEntityDataContext(SPContext.GetContext(this.Context).Web.Url);

        EntityList<ProductDocumentMapItem> dMaps = dc.GetList<ProductDocumentMapItem>("Product Document Map");

        object mappedItems = null;

        mappedItems = from m in dMaps
                      join p in dc.PEProducts on m.ProductID.Value equals p.Id.Value
                      join d in dc.ProductDocuments on m.DocID.Value equals d.Id.Value
                      where m.ProductID.Value == id && m.ProductType == "PE"
                      select new { 
                          p.Grade, 
                          d.Path, 
                          d.DocumentType, 
                          d.Title, 
                          d.Name, 
                          Language = d.Language.Title, 
                          m.Id, 
                          DocId = m.DocID };

        GridViewProducts.KeyFieldName = "Id";
        GridViewProducts.DataSource = mappedItems;
        GridViewProducts.DataBind();
    }

The following fields are nullable:

  • m.ProductID
  • m.DocID
  • d.DocumentType
  • m.Id

When I debug, none of this throws an error, but when the page loads it does: System.InvalidOperationException: Nullable object must have a value

Does this mean that one of the fields I'm selecting is null, or one of the join fields? Having checked the data, I don't think this is the case. Let me know if you need any more info from me.

1
  • I wonder if dMaps is null Commented Jan 24, 2013 at 19:24

1 Answer 1

1

System.InvalidOperationException: Nullable object must have a value

This exception is thrown when you are trying to get Value property of nullable type. So, that means one or more of following is true:

  • At least one of objects in dMaps has property ProductID equal to null
  • At least one of objects in dMaps has property DocID equal to null
  • At least one of objects in dc.PEProducts has property Id equal to null
  • At least one of objects in dc.ProductDocuments has property Id equal to null
  • Exception raised not by query
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.