在Select中返回Null [英] Nulls returned in a Select

查看:456
本文介绍了在Select中返回Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是EF的新手,并且一直在研究一些例子。以下声明运行良好。但是,当pe.pe_mi字段为null时,显示变量为null。我想要一种方法来检查它是否为空并返回一个空字符串。

谢谢所有,

Eric


return from sp in MIAScontext.Suppliers_People

Hi all,

I am new to EF and have been working on a few examples.  The statement below runs fine.  However, when the pe.pe_mi field is null then the display variable is null.  I would like a way to check if it is null and return a blank string.

Thanks all,

Eric

return (from sp in MIAScontext.Suppliers_People

join su in MIAScontext.Suppliers on sp.Suppliers.su_id 等于 su.su_id

join su in MIAScontext.Suppliers on sp.Suppliers.su_id equals su.su_id

join pe in MIAScontext.People on sp.People.pe_id equals pe.pe_id

join pe in MIAScontext.People on sp.People.pe_id equals pe.pe_id

其中 su.su_id == SupplierId

where su.su_id == SupplierId

orderby su.su_name

orderby su.su_name

选择 new PeopleSupplierList()

select new PeopleSupplierList()

{

value = pe.pe_id,

value = pe.pe_id,

display =( string )pe.pe_lastname + "," +( string )pe.pe_mi + "。 " +( string )pe.pe_firstname,

display = (string)pe.pe_lastname + ", " + (string)pe.pe_mi + ". " + (string)pe.pe_firstname,

active = pe.pe_active

active = pe.pe_active

})

.ToList< PeopleSupplierList>();

.ToList<PeopleSupplierList>();

推荐答案

Hi *,

我不确定是否有办法在LINQ to Entities中使用合并(或类似)功能(使表达式转换为此函数)。无论如何,我认为,好的方法是在这个对象的partial类中创建属性,并在这里使用一行简单的代码。在查询中执行它并不是很大的计算,你可以在客户端上进行。
Hi *,

I'm not sure, whether there's way to use coalesce (or similar) function in LINQ to Entities (to make the expression translated to this function). Anyway, I think, the good way will be create property in partial class for this object and use here a simple one line of code. It's not huge computation to do it in query, you can do it on client.


这篇关于在Select中返回Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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