问题
I have an issue with odata. When a property that is being expanded is null it would throw an exception saying it could not find a property on the object it is expanding (obviously because it is null).
I then updated Microsoft.Data.Edm to 5.6.1 as it says it has a fix for this issue. But the fix just removes any enitites from the returned data if any of the expanded properties in the entity are null.
Has anyone else had this issue an have a solution for it.
回答1:
You could use something like this:
private T HandleNull<T>(T entity) where T : class, new()
{
if (entity == null)
{
return new T();
}
return entity;
}
Usage:
return HandleNull(repo.Find(a => a.EmployeeId == key))
来源:https://stackoverflow.com/questions/23410257/odata-expand-does-not-return-entity-when-null