ASP.NET Core 2.2 OData(v7.1.0)返回的数据缺少用户定义的属性。我有一个人类,其中包含电话号码列表。 OData返回,但减去TelephoneType
。
来自MongoDb的数据正确
{
"_id" : ObjectId("5cef852944f1c9b5586851e7"),
"PersonId" : "123",
"Name" : "Alan",
"Gender" : null,
"TelNos" : [
{
"TelephoneType" : {
"Type" : "Home"
},
"PhoneNumber" : "056328499"
},
{
"TelephoneType" : {
"Type" : "Mobile1"
},
"PhoneNumber" : "00953553955"
}
]
}
public class TelephoneType
{
public string Type {get;set;}
}
public class Telephone
{
public TelephoneType PhoneType {get; set;}
public string PhoneNumber {get; set;}
}
public class Person
{
[Key]
public string PersonId {get;set;}
public string Name {get;set;}
public string Gender {get;set;}
public List<Telephone> TelNos {get; set;}
}
public static IEdmModel GetEdmModel(IServiceProvider serviceProvider)
{
ODataModelBuilder builder = new ODataConventionModelBuilder(serviceProvider);
builder.Namespace = "MyApp";
builder.EntitySet<TelephoneType>("TelephoneType")
.EntityType
.Filter()
.Count()
.Expand()
.OrderBy()
.Page()
.Select();
builder.EntitySet<Person>("Person")
.EntityType
.Filter()
.Count()
.Expand()
.OrderBy()
.Page()
.Select();
}
返回的数据:
{
"@odata.context": "http://192.168.8.51:5020/v2/odata/$metadata#Patient",
"value": [
{ "PersonId":"123", "Name": "Alan", "Gender":null,
"TelNos": [ { "PhoneNumber":"056328499" }, { "PhoneNumber":"00953553955" } ]
}
]
}