dotnet / dotnet/efcore

Nested Owned Type Contains Navigation Property - Not Work

Open
#27,175 9 comments 1 reaction 0 assignees View on GitHub
area-model-building customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

I try to define my data model much closer to domain models, but I think that Ef does not support this simple need. I worked with ownsMany, ownsOne, hasMany, hasOne, withOwner, Navigation builder, IEntityTypeConfiguration, and ... in different ways.

```C#
public class Custom
{
[Required]
public int id { get; set; }
public string name { get; set; }

public Demo demo{ get; set; }
}

[Owned()]
public class Demo
{
public virtual ICollection pDemoes{ get; set; }
}

public class PDemo
{
[Required]
public int id { get; set; }
public string name { get; set; }

[ForeignKey("Custom")]
public int CustomId{ get; set; }
public virtual Custom Custom{ get; set; }
}
```

EF Core Add-Migration Says :
```
Unable to determine the relationship represented by navigation 'Demo.pDemoes' of type 'ICollection'.
Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or
by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
```

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.