title: Stored Procedure Results Return Null When Where Clause is Added in LINQ
body: <p>I've created a stored procedure in SQL Server:</p>
  
  <pre><code>CREATE PROCEDURE PRODUCT_PROCEDURE
  
      @USERID VARCHAR(MAX)
  AS
  BEGIN
  
      SELECT distinct datawarehouse.dbo.orderformdump.itemno, basedescription,info,upc,CAST((SELECT [UNITPRICE] FROM PPPLTD.dbo.[ICPRICP] WHERE [ITEMNO] = replace([DataWarehouse].[dbo].[ORDERFORMDUMP].[ITEMNO],'-','') AND [PRICELIST] = (select top 1 priclist from PPPLTD.dbo.ARCUS where IDCUST = (select top 1 CUSTID from PPPLTD.dbo.WEBLOGINACCESS where [USER] = @USERID)) and [CURRENCY] = 'CDN' and DPRICETYPE = 1) AS DECIMAL(18,2))as price,caseqty, qty AS userquantity FROM [DataWarehouse].[dbo].[ORDERFORMDUMP] LEFT JOIN pppltd.dbo.weboeordd ON pppltd.dbo.WEBOEORDD.ITEMNO = REPLACE(datawarehouse.dbo.ORDERFORMDUMP.ITEMNO,'-','') and orduniq not in (select orduniq from pppltd.dbo.weboeordsubmit) and WEBOEORDD.ORDUNIQ in (select orduniq from pppltd.dbo.weboeordh where [user] = @USERID) LEFT JOIN DATAWAREHOUSE.dbo.webiteminfo on webiteminfo.itemno = orderformdump.itemno where (allowinbc = 'Yes' or allowinab = 'Yes') order by BASEDESCRIPTION
  
  END
  </code></pre>
  
  <p>and I've imported the procedure into my project using Entity Framework's Database First approach. It's created a model and a method inside the DbContext that executes the stored procedure for me.</p>
  
  <p>Model:</p>
  
  <pre><code>public partial class PRODUCT_PROCEDURE_Result
      {
          public string itemno { get; set; }
          public string basedescription { get; set; }
          public string info { get; set; }
          public string upc { get; set; }
          public Nullable&lt;decimal&gt; price { get; set; }
          public Nullable&lt;int&gt; caseqty { get; set; }
          public Nullable&lt;int&gt; userquantity { get; set; }
      }
  </code></pre>
  
  <p>DbContext Method:</p>
  
  <pre><code>public virtual ObjectResult&lt;PRODUCT_PROCEDURE_Result&gt; PRODUCT_PROCEDURE(string USERID)
          {
              var USERIDParameter = USERID != null ?
                  new ObjectParameter("USERID", USERID) :
                  new ObjectParameter("USERID", typeof(string));
  
              return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction&lt;PRODUCT_PROCEDURE_Result&gt;("PRODUCT_PROCEDURE", USERIDParameter);
          }
  </code></pre>
  
  <p>My question is how come when I execute <code>var products = db.PRODUCT_PROCEDURE(username).ToList()</code> alone, it returns results, but when I add a where clause to it,</p>
  
  <pre><code>var products = db.PRODUCT_PROCEDURE(username)
                  .Where
                          (item =&gt; item.basedescription.Contains(searchword) 
                           || item.info.Contains(searchword)
                           || item.itemno.Contains(searchword)
                           || item.itemno.Contains(searchword.Replace("-", ""))
                           || item.upc.Contains(searchword)).ToList();
  </code></pre>
  
  <p>it returns null and throws a NullReferenceException?</p>
  
  <p>P.S. I've checked the <code>searchword</code> variable and it contains a value, therefore that's not the issue.</p>