我有一个web api方法,它返回一个实体框架实体列表。问题是,当我使用PostMan时,api方法只返回一个json对象,即使我可以看到我的web api方法中的列表有多个对象。
public IEnumerable<EQUIPMENT> GetEquipmentWithIncidentID(int id)
{
var data = db.EQUIPMENTs.Where(d => d.INCIDENT.Id == id);
return data.ToList();//has 2 objects, both with valid EQUIPMENT data
}
这是JSON。我知道它很长,但我看到一个问题。
[
{
"$id": "1",
"$type": "System.Data.Entity.DynamicProxies.EQUIPMENT_D790835B03D8AFA64882E425140B5DF282172396D2935CAF5839D425D4A34624, EntityFrameworkDynamicProxies-DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"C_LINK_SELECTION": null,
"C_LINK_SPECIAL": {
"$type": "System.Collections.Generic.HashSet`1[[DomainModelModule.C_LINK_SPECIAL, DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$values": []
},
"DESIGNATOR": {
"$id": "2",
"$type": "System.Data.Entity.DynamicProxies.DESIGNATOR_95426D806E5286A1F68EBAA09C9ECDE07E22D2B3D1F157C8121CD09A1FDE92C0, EntityFrameworkDynamicProxies-DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"C_LINK": {
"$type": "System.Collections.Generic.HashSet`1[[DomainModelModule.C_LINK_SELECTION, DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$values": []
},
"C_LINK_SPECIAL": {
"$type": "System.Collections.Generic.HashSet`1[[DomainModelModule.C_LINK_SPECIAL, DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$values": []
},
"DIAL_DESIGNATOR": null,
"EQUIPMENT": {
"$type": "System.Collections.Generic.HashSet`1[[DomainModelModule.EQUIPMENT, DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$values": [
{
"$ref": "1"
},
{
"$id": "3",
"$type": "System.Data.Entity.DynamicProxies.EQUIPMENT_D790835B03D8AFA64882E425140B5DF282172396D2935CAF5839D425D4A34624, EntityFrameworkDynamicProxies-DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"C_LINK_SELECTION": null,
"C_LINK_SPECIAL": {
"$type": "System.Collections.Generic.HashSet`1[[DomainModelModule.C_LINK_SPECIAL, DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$values": []
},
"DESIGNATOR": {
"$ref": "2"
},
"INCIDENT": {
"$id": "4",
"$type": "System.Data.Entity.DynamicProxies.INCIDENT_48C57B72A7ABE0D4324C23DD566C1D077603126FA76A0CF847BDEE2DAAAC5CDA, EntityFrameworkDynamicProxies-DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"EQUIPMENTs": {
"$type": "System.Collections.Generic.HashSet`1[[DomainModelModule.EQUIPMENT, DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$values": [
{
"$ref": "3"
},
{
"$ref": "1"
}
]
},
"FREQUENCies": {
"$type": "System.Collections.Generic.HashSet`1[[DomainModelModule.FREQUENCY, DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$values": []
},
"LOGs": {
"$type": "System.Collections.Generic.HashSet`1[[DomainModelModule.LOG, DomainModelModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$values": []
},
"ZONE": null,
"Id": 1,
"Name": "TEST",
"IncidentProjectOrderNumber": "sdgsdg",
"FinancialCode": "sdgsdg",
"Latitude": "1254",
"Longitude": "124",
"IncidentReleaseDate": "2015-04-24T16:20:00",
"IsActive": false,
"IsCache": false
},
"Id": 2, //THIS IS THE START OF THE INFO THAT SHOULD APPEAR IN A SECOND EQUIPMENT ENTITY!!!
"SNumber": "hhhjj",
"BoxNumber": null,
"DateReleased": "2015-04-17T16:20:00",
"NFES": "sdeg",
"IssuedDate": null,
"ItemDescription": "sdeg",
"ModulationType": "FM",
"Bandwidth": "25 kHz",
"IsSpecial": false,
"RepeaterUsed": null,
"Technician": null,
"ADM": null
}
]
},
"Id": 1,
"DesignatorName": "C2",
"TXFreq": "163.3375",
"RXFreq": "167.9500",
"IsSpecial": false,
"IsCommand": false
},
"INCIDENT": {
"$ref": "4"
},
"Id": 1,//And these are the basic properties of the first equipment entity
"SNumber": "fff",
"BoxNumber": null,
"DateReleased": "2015-04-25T16:20:00",
"NFES": "sadfsadg",
"IssuedDate": null,
"ItemDescription": "sadfsadg",
"ModulationType": "AM",
"Bandwidth": "None",
"IsSpecial": false,
"RepeaterUsed": null,
"Technician": null,
"ADM": null
},
{
"$ref": "3"
}
顶级实体对象(EQUIPMENT),具有属性&#34; SNumber&#34;,当它返回json时看起来有些未知原因,其他设备对象部分嵌套在第一个对象中,但我不明白为什么。
我不知道&#34; $ ref:3&#34;是
有什么想法吗?我不知道该尝试什么。感谢。
答案 0 :(得分:0)
我通过添加
修复了它 Configuration.LazyLoadingEnabled = false;
到我的DbContext()。