在EF Core 6 Fluent API中配置具有继承关系的值对象

发布于 2025-01-31 05:34:59 字数 962 浏览 3 评论 0原文

我正在尝试在我的项目之一中实现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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以畏孤独 2025-02-07 05:34:59

在您的配置中使用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 the DaysOfMonth property

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文