dotnet / dotnet/efcore

Properties discovered by HasKey or similar are not discovered as primitive collections

Open
#31,417 0 comments 0 reactions 0 assignees View on GitHub
area-primitive-collections
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

For example, assuming `CollectionCompanyId` and `CollectionTenantId are not discovered as properties by convention (for example, they are fields), then:

```C#
modelBuilder.Entity(
b =>
{
b.HasKey(e => new { e.CollectionCompanyId, e.CollectionTenantId });
});
```

Will add the properties to the model, but as non-collection primitive properties. The workaround is to explicit map the primitive collections first:

```C#
modelBuilder.Entity(
b =>
{
b.PrimitiveCollection(e => e.CollectionCompanyId);
b.PrimitiveCollection(e => e.CollectionTenantId);
b.HasKey(e => new { e.CollectionCompanyId, e.CollectionTenantId });
});
```

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.