LinQ ile null değerlerin toplanması

Linq da kullanılan .Sum() ifadesi normalde null değerleri toplarken hata verir, fakat  biz linq da bu değerlerin null olabileceğini belirtirsek bu hata mesajında kuturlmuş oluruz.

 

 

Program çalıştırıldığı aşağıdaki gibi bir çıktı alınır. Görüldüğü gibi son kişinin değerlerinin toplamı null dur.

 

 kaynak : http://weblogs.asp.net/zeeshanhirani/archive/2008/07/15/applying-aggregates-to-empty-collections-causes-exception-in-linq-to-sql.aspx

Add comment

The file '/Custom/Widgets/Calendar/widget.cshtml' does not exist.The file '/Custom/Widgets/Category list/widget.cshtml' does not exist.The file '/Custom/Widgets/Tag cloud/widget.cshtml' does not exist.The file '/Custom/Widgets/Page List/widget.cshtml' does not exist.The file '/Custom/Widgets/Month List/widget.cshtml' does not exist.