简体   繁体   中英

Nullable type linq c#

in my database there is some row which is null and how can i use nullable type or how can i skip nullable row in linq? but i prefer to use nullable type rather than skip rows (see image)

在此处输入图片说明

You can't cast null to a non nullable type (decimal)

You should update your generic type to a nullable type like the below:

From

 let floatingPNL1 = b.Field<decimal>("FloatingPNL")

To

 let floatingPNL1 = b.Field<decimal?>("FloatingPNL")

Another option would be to use an ORM such as dapper, much easier to use and handles the object mapping for you.

Decimal? should be a nullable type

Use Nullable<decimal> instead of decimal . Read more here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM