EF Core 映射关系及取数据(急等高手)

佛祖的木鱼 佛祖的木鱼 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我现在准备用EF Core从现有的数据库里取数据出来,有三张表:

其中,一个JobHeader可以包含多个JobOperation,关联键是JobNum, 同样的一个JobOperation,可以包含多个OprTransactions,关联键是JobNum+OpCode

请问我怎样用EF Core来定义映射关系并取值呢?

public class JobHeader
{
[Key]
public string JobNum { get; set; }
public string PartNum { get; set; }
}

public class JobOperation
{
[Key]
public int Id { get; set; }
public string JobNum { get; set; }
public string OpCode { get; set; }

}

public class OprTransactions
{
[Key]
public int Id { get; set; }
public string JobNum { get; set; }
public string OpCode { get; set; }
public string TransType { get; set; }
}

希望取值的内容如下:

{
"jobNum": "000025172-0009",
"partNum": "CIB-75-00024KT-A",
"JobOperation": [
{
"jobNum": "000025172-0009",
"opCode": "NF01",
"OprTransactions": [
{
"id": 1,
"jobNum": "000025172-0009",
"opCode": "NF01",
"transType": "OPRSTART",
},
{
"id": 2,
"jobNum": "000025172-0009",
"opCode": "NF01",
"transType": "OPREND",
}
]
},
{
"jobNum": "000025172-0009",
"opCode": "NF34",
"OprTransactions": [
{
"id": 3,
"jobNum": "000025172-0009",
"opCode": "NF34",
"transType": "OPRSTART",
}
]
}
]
}
...全文

相关推荐

评论 10
收藏 已收藏
分享
返回顶部
佛祖的木鱼
LINQ 8,492 成员 4,736 内容