title: Optional Parameters with EF Core FromSql
body: <p>Is it possible to use EF Core FromSql to execute a stored procedure that has optional parameters?</p>
  
  <p>I have been testing out a simple scenario to use as a template for updating old EF6 calls to EF Core calls.  The test example I am using as a proof of concept:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[TestNullableParameters] 
      @addressId int = null,
      @city nvarchar(100) = null,
      @createdByUserId int
  AS
  BEGIN
      select * from CRM..Address a
      where (@addressId is null or a.AddressId = @addressId)
      and (@city is null or a.City like @city)
      and a.CreatedByUserId = @createdByUserId
  END
  </code></pre>
  
  <p>My test code that calls this proc:</p>
  
  <pre><code>[Test]
  public void TestNullableParameters()
  {
      var procName = "exec CRM..TestNullableParameters ";
      var context = _testContainer.Resolve&lt;CRM2Context&gt;();
  
      var addressId = new SqlParameter("@addressId", 182);
      var createdByUserId = new SqlParameter("@createdByUserId", 1620);
      var parameters = new[] {addressId, createdByUserId};
      var result = context.Address.FromSql(procName, parameters).ToList();
  }
  </code></pre>
  
  <p>This code does not work, as it states the procedure requires "@createdByUserId", which was not supplied -- it attempts to map createdByUserId to @city, and then has no value to map to @createdByUserId.</p>
  
  <p>If I try to define a parameter @city with value null, it states that the procedure requires a non-null value for @city.</p>
  
  <p>If I try to explicitly add a parameter list with only @addressId and @createdByUserId, it states that it is missing non-nullable @city.</p>