0

I write this code in C# with LINQ. Type of innerResult2 is IEnumerable<out T>

this part of code has exception :

Nullable object must have a value

var innerResult2 = (from Vw_WorkFlow_Cartable in innerResult
 select new
 {
     isedit = (bool?)Convert.ToBoolean((
       (from v in view8.Table.AsEnumerable()
        where
          v.Field<bool?>("SendByRequester") == true 
        select new
        {
            ActivityID = v.Field<Guid>("ActivityID")
        })
        .Contains(new 
        { 
            ActivityID = (System.Guid)Vw_WorkFlow_Cartable.Field<Guid?>("ActivityID") 
        }) 
        ? true : false))
 })
StuartLC
  • 104,537
  • 17
  • 209
  • 285
  • Can you edit your question so the code is more readable? – MacakM Nov 02 '16 at 05:59
  • Is `"ActivityId"` `null`? You cast from nullable (`Guid?`) to non-nullable (`Guid`) type, if it's null then it will give you error. – Niyoko Nov 02 '16 at 06:01
  • change v.Field("SendByRequester") == true to v.Field("SendByRequester").HasValue && v.Field("SendByRequester") == true – A.T. Nov 02 '16 at 06:02
  • `(from ...where... select new {...}).Contains(new {...})` this code should never work, what is the comparer? and why are you trying to `Convert.ToBoolean(bool boolValue)`? – Takahiro Nov 02 '16 at 06:08
  • and `Contains(...) ? true: false` is another redundant. – Takahiro Nov 02 '16 at 06:13

0 Answers0