gpt4 book ai didi

c# - 如何使用 NPoco 在同一个表中保存嵌套对象?

转载 作者:太空狗 更新时间:2023-10-29 23:31:02 24 4
gpt4 key购买 nike

我有这样一个类:

public class AuthEntity 
{
public int Id { get; set; }

public AuthResource Resource { get; set; }

public int ActionId { get; set; }
}

AuthResource 在哪里:

public class AuthResource 
{
public long ResourceId { get; private set; }

public int ResourceType { get; private set; }
}

存储数据的表有以下字段:

  • 身份证
  • 资源编号
  • 资源类型
  • Action 编号

我可以很好地阅读 AuthEntity(包括 Resource 属性),但我不知道如何插入 AuthEntity 记录。 NPoco 说没有 Resource 字段。如何将嵌套对象字段映射到表字段?

谢谢

最佳答案

NPoco 文档说您可以使用映射到嵌套对象 来做到这一点。

db.Fetch<AuthEntity, AuthResource>("select query to db")

此外,您还必须将 AuthResource 更改为

public class AuthResource
{
public long ResourceId { get; set; }
public int ResourceType { get; set; }
}

关于c# - 如何使用 NPoco 在同一个表中保存嵌套对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25233341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com