Hello,
This is the code we are using, I left out some properties to make it more readable.
This is our entity:
namespace Domain.EntityClasses
{
/// <summary>Class which represents the entity 'dbo.PrePaidTransaction'.</summary>
public partial class PrePaidTransaction : CommonEntityBase
{
/// <summary>Method called from the constructor</summary>
partial void OnCreated();
/// <summary>Initializes a new instance of the <see cref="PrePaidTransaction"/> class.</summary>
public PrePaidTransaction() : base()
{
OnCreated();
}
/// <summary>Gets or sets the BalanceNew field. </summary>
public System.Decimal BalanceNew { get; set; }
/// <summary>Gets or sets the BalanceOld field. </summary>
public System.Decimal BalanceOld { get; set; }
/// <summary>Gets or sets the Credits field. </summary>
public System.Decimal Credits { get; set; }
/// <summary>Gets or sets the Description field. </summary>
}
}
Mapping:
protected virtual void MapPrePaidTransaction(EntityTypeBuilder<PrePaidTransaction> config)
{
config.ToTable("PrePaidTransaction");
config.Property(t => t.Credits);
config.Property(t => t.BalanceOld);
config.Property(t => t.BalanceNew);
}
Table:
CREATE TABLE [dbo].[PrePaidTransaction](
[Credits] [decimal](18, 3) NOT NULL,
[BalanceOld] [decimal](18, 3) NOT NULL,
[BalanceNew] [decimal](18, 3) NOT NULL
)
Also, the context itself was not changed, just the auto-generated code.
Our injection (ConfigureServices in Startup.cs)
services.AddDbContext<OurContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("ConnectionString")));
services.AddScoped<DbContext, OurContext>();
In a unit test environment, I am also not really able to reproduce this, but when we deploy to Azure, we see these exceptions popping up in Sentry (warnings). Also when running the API locally, we can see these warnings in the DEBUG console.
More details:
- Web API project using .NET Core 3.1
- Persistence and Model projects using .NET Standard 2.1
Frank