dotnet / dotnet/efcore

Confusing exception messages when failing to obtain DbSet with shared-type entity types

Open
#29,970 0 comments 0 reactions 0 assignees View on GitHub
area-dbcontext
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

With a normal type and a shared-type entity type:

```C#
modelBuilder.Entity();
modelBuilder.SharedTypeEntity>("Shared", b =>
{
b.Property("Id");
});
```

Confusing (incorrect) messages are generated when attempting to use a DbSet with the correct type but the wrong set name.

```C#
var set = context.Set>("Foo").ToList();
```

```
Cannot create a DbSet for 'Dictionary' because it is configured as an shared-type entity type.
Access the entity type via the 'Set' method overload that accepts an entity type name.
```

```C#
var set = context.Set("Foo").ToList();
```

```
Cannot create a DbSet for 'Blog' because this type is not included in the model for the context. However the model contains
an entity type with the same name in a different namespace: 'Blog'.
```

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.