【问题标题】:Merge two linq results and convert into json object合并两个 linq 结果并转换为 json 对象
【发布时间】:2021-03-17 06:20:54
【问题描述】:
var entity = ctx.CDB.Admin_LookupEntities.AsQueryable().FirstOrDefault(x => x.Type == "FlexTriggerEventNudgeEmail");
List<Guid> documentIds = ctx.IDB.DocumentNudgeEmailIntersects.AsQueryable().Select(x => x.Document_RecordID).ToList();

以上是我的两个 linq 结果,我需要将它们合并并作为 json 对象添加到 mergedata 中

{
"lookupEntity_RecordId": "00000000-0000-0000-0000-000000000000",
"DocumentRecordIds":["00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000"]
}

并在此处添加 mergeData.Add("AdditionalData", "");

【问题讨论】:

  • 这里的mergeData是什么?它是一个单独的类吗?
  • 是的,它在一个单独的类中
  • 我的意思是这个类中有哪些属性,因为当您将上述结果添加到此 mergeData 列表中时,列表的类型应该包含您共享的上述两个属性。
  • mergedata 是一个字典对象。在该对象中,我想发送额外的数据作为键,这将提供上述 json 对象。
  • 试试这个:mergeData.Add("AdditionalData", new {lookupEntity_RecordId = entity, DocumentRecordIds = documentIds });

标签: asp.net-mvc linq asp.net-core linq-to-sql


【解决方案1】:

使用循环将第一个列表值添加到第一个列表。第二个列表将添加到第一个列表中。 可能这个链接会解决你的问题。 JSON 和 ViewModel 映射

https://findandsolve.com/articles/jwt-authentication-in-asp.net-core-aef04bc0467b2-aef0504aae5bd

【讨论】:

    猜你喜欢
    • 2019-01-25
    • 2018-01-14
    • 2016-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2019-12-17
    相关资源
    最近更新 更多