OData Expand Does Not Return Entity When Null

拜拜、爱过 提交于 2019-12-25 09:55:02

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!