Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] 支持从属实体 #1859

Open
sangyuxiaowu opened this issue Jul 16, 2024 Discussed in #1858 · 0 comments
Open

[Feature] 支持从属实体 #1859

sangyuxiaowu opened this issue Jul 16, 2024 Discussed in #1858 · 0 comments

Comments

@sangyuxiaowu
Copy link

sangyuxiaowu commented Jul 16, 2024

Feature 特性

希望 FreeSql 能够支持从属实体(Owned Entity),类似于 EF Core 中的实现,使得从属实体的属性可以映射为拥有实体表中的列。

public class Order
{
    public int Id { get; set; }
    public StreetAddress ShippingAddress { get; set; }
}

[Owned]
public class StreetAddress
{
    public string Street { get; set; }
    public string City { get; set; }
}

简要描述原因

EF Core 支持从属实体(Owned Entity),使得从属实体的属性可以直接映射为拥有实体表中的列,这种方式使得数据模型更加紧凑和易于管理,同时也简化了数据库的结构。在 FreeSql 中实现类似功能可以让开发者更方便地使用从属实体,并提高数据模型的灵活性和可维护性。

虽然 FreeSql 当前可以自定义类型转换为json,但在某些场景也存在一些不便利的地方。

使用场景

在开发过程中,经常需要使用从属实体来表示复杂类型的属性,例如地址、联系方式等。通过支持从属实体,可以将这些复杂类型的属性直接映射为拥有实体表中的列,避免创建额外的表,简化数据库结构。

public class Customer
{
    public int Id { get; set; }
    public ContactInfo Contact { get; set; }
}

[Owned]
public class ContactInfo
{
    public string Phone { get; set; }
    public string Email { get; set; }
}

Discussed in #1858

Originally posted by sangyuxiaowu July 15, 2024
类似EF Core这样的处理,如何实现呢?
https://learn.microsoft.com/zh-cn/ef/core/modeling/owned-entities#configuring-types-as-owned

public class Order
{
    public int Id { get; set; }
    public StreetAddress ShippingAddress { get; set; }
}

[Owned]
public class StreetAddress
{
    public string Street { get; set; }
    public string City { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant