当为空时,OData展开不返回实体 [英] OData Expand Does Not Return Entity When Null

查看:92
本文介绍了当为空时,OData展开不返回实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对odata有问题.当正在扩展的属性为null时,它将引发异常,表明无法在正在扩展的对象上找到属性(显然是因为它为null).

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).

然后我将Microsoft.Data.Edm更新为5.6.1,因为它说有针对此问题的修复程序.但是,如果该实体中的任何扩展属性为空,则此修复程序只会从返回的数据中删除所有实体.

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.

推荐答案

您可以使用以下内容:

    private T HandleNull<T>(T entity) where T : class, new()
    {
        if (entity == null)
        {
            return new T();
        }
        return entity;
    }

用法:

return HandleNull(repo.Find(a => a.EmployeeId == key))

这篇关于当为空时,OData展开不返回实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆