dotnet / dotnet/efcore

Exception message for type mismatches

Open
#35,846 1 comment 0 reactions 1 assignee Claimed by @AndriySvyryd View on GitHub
area-type-mapping customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

### What problem are you trying to solve?

Hi, when specifying a CLR type that does not match the SQL type, like:

```csharp
public class Item
{
[Column(TypeName = "int")]
public string? Count { get; set; }
}
```

EF Core throws a `System.InvalidOperationException` with the message:

```text
The property 'Item.Count' could not be mapped because it is of type 'string', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
```

However, `string` is a supported type, so this message seems a bit confusing (this applies to all types, `string` is just an example).

### Describe the solution you'd like

An error message that mentions a type mismatch.

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.