Blazor Server - System.InvalidCastException: Unable to cast object of type 'System.Double' to type 'System.Single'.

Cenk 946 Reputation points


In my Blazor server application, I am trying to get the records from RazerReconciliation table as follows. I couldn't figure out why I am getting this error.

public async Task<List<RazerReconciliations>> GetOldReconsAsync()
      var result = await _oyunPalasContext.RazerReconciliation.ToListAsync();
      return result;

Here is the model;

public class RazerReconciliations
        public string? PID { get; set; }
        public string? ProductName { get; set; }
        public float ProductAmount { get; set; }
        public Guid ReferenceNo { get; set; }
        public int Quantity { get; set; }
        public DateTime TransactionDateTime { get; set; }
        public string? Explanation { get; set; }


Here is the table:

CREATE TABLE [dbo].[RazerReconciliation](
	[PID] [nvarchar](50) NULL,
	[ProductName] [nvarchar](200) NULL,
	[ProductAmount] [float] NULL,
	[ReferenceNo] [uniqueidentifier] NOT NULL,
	[Quantity] [int] NOT NULL,
	[TransactionDateTime] [datetime] NULL,
	[Explanation] [varchar](200) NULL

Here is the Context:

public virtual DbSet<RazerReconciliations> RazerReconciliation { get; set; } = null!;
Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
678 questions
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,325 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,981 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 110.1K Reputation points

    According to, try using float in SQL and double in C#.

    By the way, maybe decimal datatypes are more suitable.

    0 comments No comments