隐式转换List< int?>列出< int> [英] Implicit convert List<int?> to List<int>
本文介绍了隐式转换List< int?>列出< int>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Linq to Entities.
I am using Linq to Entities.
具有一个实体"Order",该实体具有可空列"SplOrderID".
Have an entity "Order" which has a nullable column "SplOrderID".
我的订单列表查询为
List<int> lst = Orders.where(u=> u.SplOrderID != null).Select(u => u.SplOrderID);
我理解这是因为SplOrderID是可为空的列,因此select方法返回可为空的int.
I understand it is because SplOrderID is a nullable column and thus select method returns nullable int.
我只是希望LINQ不会很聪明.
I am just expecting LINQ to be little smart.
我应该如何处理?
推荐答案
选择属性时,只需获取可为空的值即可:
As you are selecting the property, just get the value of the nullable:
List<int> lst =
Orders.Where(u => u.SplOrderID != null)
.Select(u => u.SplOrderID.Value)
.ToList();
这篇关于隐式转换List< int?>列出< int>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文