在EF Core 6 Fluent API中配置具有继承关系的值对象
我正在尝试在我的项目之一中实现DDD,在该项目中,我正在努力在EF-Core 6 Fluent API中配置值对象。
我的值对象是抽象类型的时间表,它具有混凝土类型,例如每日,每月等。
public abstract class Schedule : ValueObject
{
public DateOnly StartFrom { get; init; }
}
public class Monthly : Schedule
{
public List<int> DaysOfMonth { get; private set; }
}
// Entity which owns the Value Object :-
public class SubscribedItem : Entity
{
public Schedule Schedule { get; private set; }
}
public class SubscribedItemEntityTypeConfiguration :
IEntityTypeConfiguration<SubscribedItem>
{
public void Configure(EntityTypeBuilder<SubscribedItem> builder)
{
builder.OwnsOne(p => p.Schedule, pp =>
{
pp.Property(ppp => ppp.StartFrom).IsRequired();
// How to configure concrete type Monthly value object.
});
}
}
如何配置混凝土类型值对象。 即我想要每月的时间表类型daysofmonth,以序列化和去序列化,同时保存和从数据库中检索
I am trying to implement DDD in one of my project where I am struggling to configure value object in ef-core 6 fluent api.
My value Object is a abstract type Schedule and it has concrete type such as Daily, Monthly etc.
public abstract class Schedule : ValueObject
{
public DateOnly StartFrom { get; init; }
}
public class Monthly : Schedule
{
public List<int> DaysOfMonth { get; private set; }
}
// Entity which owns the Value Object :-
public class SubscribedItem : Entity
{
public Schedule Schedule { get; private set; }
}
public class SubscribedItemEntityTypeConfiguration :
IEntityTypeConfiguration<SubscribedItem>
{
public void Configure(EntityTypeBuilder<SubscribedItem> builder)
{
builder.OwnsOne(p => p.Schedule, pp =>
{
pp.Property(ppp => ppp.StartFrom).IsRequired();
// How to configure concrete type Monthly value object.
});
}
}
How to configure concrete type value object.
i.e. I want in Monthly Schedule Type DaysOfMonth to serialize and de-serialize while saving and retrieving from Database
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的配置中使用
pp.ownsone
,用于“值对象”导航属性。但是,您还需要设置一个值转换用于daysofmonth
属性Use
pp.OwnsOne
in your configuration for the value object navigation property. However, you need also to set up a value conversions for theDaysOfMonth
property