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))
 })
5
  • Can you edit your question so the code is more readable? Commented Nov 2, 2016 at 5:59
  • Is "ActivityId" null? You cast from nullable (Guid?) to non-nullable (Guid) type, if it's null then it will give you error. Commented Nov 2, 2016 at 6:01
  • change v.Field<bool?>("SendByRequester") == true to v.Field<bool?>("SendByRequester").HasValue && v.Field<bool?>("SendByRequester") == true Commented Nov 2, 2016 at 6: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)? Commented Nov 2, 2016 at 6:08
  • and Contains(...) ? true: false is another redundant. Commented Nov 2, 2016 at 6:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.