dotnet / dotnet/efcore

"No store type was specified for the decimal property" warning with `HasConversion<string>()` specified for property when creating a new migration

Open
#33,553 1 comment 0 reactions 1 assignee Assigned to @AndriySvyryd View on GitHub
area-model-building customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

A model containing a decimal property that is converted to a string before being stored in the database gives the following warning when adding a new migration.
```
No store type was specified for the decimal property 'Value' on entity type 'Entity'. This will cause values to be silently truncated if
they do not fit in the default precision and scale. Explicitly specify the SQL server column type that can accommodate all the values in
'OnModelCreating' using 'HasColumnType', specify precision and scale using 'HasPrecision', or configure a value converter using 'HasConversion'.
```
```csharp
using Microsoft.EntityFrameworkCore;

Console.WriteLine("Hello, World!");

public class Context : DbContext
{
public DbSet Entities { get; set; } = null!;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer("Server=.;Database=Test;Integrated Security=True;");
base.OnConfiguring(optionsBuilder);
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity()
.Property(x => x.Value)
.HasConversion();
}
}

public class Entity
{
public Guid Id { get; set; }
public decimal Value { get; set; }
}
```

```xml


Exe
net6.0
enable
enable




all
runtime; build; native; contentfiles; analyzers; buildtransitive


```

If you have quite a few of these properties, these warnings hide other important warnings that may pop up when creating migrations.

I was able to replicate this on .NET 6, v6.0.29 and .NET 7, v7.0.18. I could not replicate it using .NET 8, v8.0.4. My real code is still on .NET 6 at the moment.

I couldn't find any specific PR that seemed to be responsible for resolving the issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.