Inserting small float value to SQL Server using C# and Entity Framework
<p>My code is like this.</p>

<pre><code>public class MyDbContext : DbContext
{
    public virtual DbSet&lt;CurrentData&gt; CurrentData { get; set; }
}

public class CurrentData
{
    public int ID { get; set; }
    public DateTime Time { get; set; }
    public float Value { get; set; }
}

...

float f = 1.37E-40f;

using (var context = new MyDbContext())
{
    var data = new CurrentData() { ID = 100, Time = DateTime.Now, Value = f };
    context.CurrentData.Add(data);

    var result = context.SaveChanges();
}
</code></pre>

<p>It raises exception on <code>SaveChanges()</code> because of the small float value.</p>

<blockquote>
  <p>The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 4 (\"@1\"): The supplied value is not a valid instance of data type real. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.</p>
</blockquote>

<p>If I change <code>f</code> to 0, it works properly.</p>

<p>When I checked SQL Server's <code>REAL</code> type range, the minimum positive value is 1.18E-38.</p>

<p><a href="https://msdn.microsoft.com/en-us/library/ms173773.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/ms173773.aspx</a></p>

<p>So if float value in C# is smaller than 1.18E-38, the exception occurs.</p>

<p>I changed <code>f</code> value like this</p>

<pre><code>if (f &gt; 0 &amp;&amp; f &lt; 1.18E-38f)
    f = 0;
else if (f &lt; 0 &amp;&amp; f &gt; -1.18E-38f)
    f = 0;
</code></pre>

<p>But I think it doesn't look good.</p>

<p>What will be better solution?</p>

<p>I tested using <code>SqlDataAdapter</code> instead of Entity Framework, and got same exception.</p>

<p>I used EF v6.1.3 and .NET 4.5.1 with SQL Server 2012.</p>