我有一个这样的课:
public class AuthEntity
{
public int Id { get; set; }
public AuthResource Resource { get; set; }
public int ActionId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
AuthResource在哪里:
public class AuthResource
{
public long ResourceId { get; private set; }
public int ResourceType { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
存储数据的表具有以下字段:
我可以很好地阅读AuthEntity(包括Resource属性),但我不知道如何插入AuthEntity记录.NPoco说没有资源字段.如何将嵌套对象字段映射到表字段?
谢谢
您的表结构表明 ResourceId 和 ResourceType 是 AuthEntity 的成员,而不是单独的类。如果您想将 AuthResource 作为一个单独的类,您可以使 AuthEntity 继承自 AuthResource 例如
\n\npublic class AuthResource\n{\n public long ResourceId { get; private set; }\n public int ResourceType { get; private set; }\n}\n\npublic class AuthEntity : AuthResource\n{\n public int Id { get; set; } \n public int ActionId { get; set; }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这样 AuthEntity 将包含您希望它具有的 ResourceId 和 ResourceType 值,并且 AuthResource 可以重新用于实现相同结构的其他类,在我看来,这就是您\xe2\x80\x99正在寻找的为了。
\n