[英]Entity Framework Core: Owned type that has navigation properties
I have some classes:我有一些课程:
public class Project
{
public TimeLine TimeLine { get; set; };
}
public class TimeLine
{
public ICollection<TimeLinePhases> TimeLinePhases { get; set; };
}
public TimeLinePhase
{
}
The class Project
owns TimeLine
and this all works fine until I specify the navigation between TimeLine
and TimeLinePhase
. class
Project
拥有TimeLine
,这一切工作正常,直到我指定TimeLine
和TimeLinePhase
之间的导航。
Fluent API code that specifies TimeLine
is owned: Fluent API 指定
TimeLine
拥有的代码:
builder.Owned<TimeLine>();
builder.entity<Project>().OwnsOne(p => p.TimeLine);
I get this error:我收到此错误:
InvalidOperationException: Unable to determine the relationship represented by navigation 'TimeLine.TimeLinePhase' of type 'ICollection'.
InvalidOperationException:无法确定类型为“ICollection”的导航“TimeLine.TimeLinePhase”表示的关系。 Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
手动配置关系,或使用“[NotMapped]”属性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”忽略此属性。
So then I specify the relation between TimeLine
and TimeLinePhase
like this:然后我指定
TimeLine
和TimeLinePhase
之间的关系,如下所示:
builder
.Entity<TimeLine>()
.HasMany(t => t.TimeLinePhase)
.WithOne()
.IsRequired(false);
But now I get this error:但现在我得到这个错误:
The entity type 'TimeLine' cannot be configured as non-owned because it has already been configured as a owned.
实体类型“TimeLine”不能配置为非拥有,因为它已被配置为拥有。 Use the nested builder in
OwnsOne
orOwnsMany
on the owner entity type builder to further configure this type在所有者实体类型构建器上使用
OwnsOne
或OwnsMany
中的嵌套构建器来进一步配置此类型
How can I have TimeLine
as an owned type, and still have the relation between TimeLine
and TimeLinePhases
?我怎样才能将
TimeLine
作为拥有的类型,并且仍然具有TimeLine
和TimeLinePhases
之间的关系?
I brief search revealed an answer.我简单的搜索发现了一个答案。 It seems configuring an owned type having a collection is not allowed.
似乎不允许配置具有集合的自有类型。 The problem being an owned type cannot act as a principal entity for the collection
拥有类型的问题不能充当集合的主要实体
See comments by AjVickers at this GitHub page: https://github.com/do.net/efcore/issues/27175请参阅 AjVickers 在此 GitHub 页面上的评论: https://github.com/do.net/efcore/issues/27175
It seems a redesigned datastructure is needed.似乎需要重新设计数据结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.