【发布时间】:2020-07-09 22:07:33
【问题描述】:
我有两个模型,一个 SettingCollection 和一个 SettingValue。 SettingCollection 有许多 SettingValue。这就是这种关系的建立。
public class SettingCollection
{
public int SettingCollectionId { get; set; }
public string Name { get; set; }
public string Key { get; set; }
public int Priority { get; set; }
public ICollection<SettingValue> SettingValues {get; set; }
}
和
public class SettingValue
{
public int SettingValueId { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public int SettingCollectionId { get; set; }
public SettingCollection SettingCollection { get; set; }
}
要在一次调用中创建新的 SettingCollection 和 SettingValues,我将发布以下有效负载:
{
"Name": "Company Collection",
"Key": "company_collection",
"Priority": 3,
"SettingValues":
[{"Name": "Is this true", "Value": "True"}]
}
我的回答是:
System.Text.Json.JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerCycleDetected(Int32 maxDepth)
这只是我不能做的事情,必须使用 NewtonSoft 来提取控制器中的原始数据吗?
谢谢!
【问题讨论】:
标签: c# entity-framework-core asp.net-core-webapi