ToQueryString parameter values with float (and maybe real?) are wrong
See original GitHub issueIt is important that these values are correct if you rely on ToQueryString (DebugView) as a troubleshooting tool.
CREATE TABLE[dbo].[FloatTable]
(
[Id] INT IDENTITY NOT NULL,
[Data] FLOAT NULL
);
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Linq;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
using var nw = new NWContext();
// Alter this value for each run
double? testval = 4.5655d;
nw.FloatTables.Add(new FloatTable
{
Data = testval,
});
nw.SaveChanges();
var query = nw.FloatTables.Where(x => x.Data == testval).ToQueryString();
var found = nw.FloatTables.SingleOrDefault(x => x.Data == testval);
}
}
public partial class FloatTable
{
public int Id { get; set; }
public double? Data { get; set; }
}
public partial class NWContext : DbContext
{
public NWContext()
{
}
public virtual DbSet<FloatTable> FloatTables { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source=.\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True", x => x.UseNetTopologySuite())
.LogTo(Console.WriteLine)
.EnableSensitiveDataLogging();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new FloatTableConfiguration());
}
}
public partial class FloatTableConfiguration : IEntityTypeConfiguration<FloatTable>
{
public void Configure(EntityTypeBuilder<FloatTable> entity)
{
entity.ToTable("FloatTable");
}
}
}
ToQueryString:
DECLARE @__testval_0 float = 4.5654000000000003E0;
SELECT[f].[Id], [f].[Data]
FROM[FloatTable] AS[f]
WHERE[f].[Data] = @__testval_0
EF Core log:
Executing DbCommand[Parameters =[@__testval_0 = '4.5654'(Nullable = true)], CommandType = 'Text', CommandTimeout = '30']
SELECT TOP(2) [f].[Id], [f].[Data]
FROM[FloatTable] AS[f]
WHERE[f].[Data] = @__testval_0
EF Core version: 6.0.3 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 6.0
Issue Analytics
- State:
- Created a year ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
c# - Incorrect float data is inserted
In my SQL Server i have a table with a column called FloatValue With a Float data type. I update this value from...
Read more >ToQueryString() "optimizes" the Where clause in an ...
When calling ToQueryString() with a parameter that is known to be invalid (for example, null on a required column), that Where clause is ......
Read more >Strict configuration · Issue #1098 · pydantic ...
In #284, the reason given for not including a strict mode config was that pydantic would no longer be able to just call...
Read more >SolrParams (Solr 8.9.0 API)
SolrParams is designed to hold parameters to Solr, often from the request ... Returns the Float value of the param, or null if...
Read more >ModifiableSolrParams (Solr 8.0.0 API)
Returns an Iterator over the parameter names. String[], getParams(String param). returns an array of the String values of a param, or ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @ErikEJ. I’m guessing SqlClient is truncating the parameter. We will discuss.
@ajcvickers Great!