Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. An expression tree lambda may not contain a null propagating operator

An expression tree lambda may not contain a null propagating operator

Scheduled Pinned Locked Moved .NET (Core and Framework)
linqhelpquestioncsharpdata-structures
3 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    simpledeveloper
    wrote on last edited by
    #1

    I am getting the following error when I am write the following Linq - can somebody please suggest me to write the same without getting the error. My Linq is as follows:

                myOrphanList =
                        (
                            from v in allViolations
                            from r in allInspectionResults
                            from i in allItems
                            where
                                r.InspectionResultId == i.InspectionResultId &&
                                i.InspectionItemId == v.InspectionItemId
                            select new OrphanViolationsReport
                            {
                                ViolationId = v.ViolationId,
                                ViolationNumber = v.ViolationNumber,
                                ViolationDate = v.ViolationDate,
                                ViolationType = v.ViolationType.ViolationTypeCode,
                                ItemYear = i.ItemYear,
                                ItemMakeManufacturer = i.ItemMakeManufacturer,
                                ItemModel = i.ItemModel,
                                VIN = i.VIN,
                                PIN = i.PIN,
                                InspectionResultId = r.InspectionResultId,
                                InspectionResultNumber = r.InspectionRequestNumber,
                                DealerDmvNumber = r.DealerDmvNumber,
                                InspectedCompanyName = (from a in contacts where a.ContactId == r.InspectedCompanyDataId select a.FirstName)?.FirstOrDefault()
                            }
                        ).ToList();
    

    At the line "InspectedCompanyName = (from a in contacts where a.ContactId == r.InspectedCompanyDataId select a.FirstName)?.FirstOrDefault()" I am getting following error - how can I get rid of it - thank you

    An expression tree lambda may not contain a null propagating operator

    Any help please

    L B 2 Replies Last reply
    0
    • S simpledeveloper

      I am getting the following error when I am write the following Linq - can somebody please suggest me to write the same without getting the error. My Linq is as follows:

                  myOrphanList =
                          (
                              from v in allViolations
                              from r in allInspectionResults
                              from i in allItems
                              where
                                  r.InspectionResultId == i.InspectionResultId &&
                                  i.InspectionItemId == v.InspectionItemId
                              select new OrphanViolationsReport
                              {
                                  ViolationId = v.ViolationId,
                                  ViolationNumber = v.ViolationNumber,
                                  ViolationDate = v.ViolationDate,
                                  ViolationType = v.ViolationType.ViolationTypeCode,
                                  ItemYear = i.ItemYear,
                                  ItemMakeManufacturer = i.ItemMakeManufacturer,
                                  ItemModel = i.ItemModel,
                                  VIN = i.VIN,
                                  PIN = i.PIN,
                                  InspectionResultId = r.InspectionResultId,
                                  InspectionResultNumber = r.InspectionRequestNumber,
                                  DealerDmvNumber = r.DealerDmvNumber,
                                  InspectedCompanyName = (from a in contacts where a.ContactId == r.InspectedCompanyDataId select a.FirstName)?.FirstOrDefault()
                              }
                          ).ToList();
      

      At the line "InspectedCompanyName = (from a in contacts where a.ContactId == r.InspectedCompanyDataId select a.FirstName)?.FirstOrDefault()" I am getting following error - how can I get rid of it - thank you

      An expression tree lambda may not contain a null propagating operator

      Any help please

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It needs an actual value. If you Google the error message you will find a number of suggestions.

      1 Reply Last reply
      0
      • S simpledeveloper

        I am getting the following error when I am write the following Linq - can somebody please suggest me to write the same without getting the error. My Linq is as follows:

                    myOrphanList =
                            (
                                from v in allViolations
                                from r in allInspectionResults
                                from i in allItems
                                where
                                    r.InspectionResultId == i.InspectionResultId &&
                                    i.InspectionItemId == v.InspectionItemId
                                select new OrphanViolationsReport
                                {
                                    ViolationId = v.ViolationId,
                                    ViolationNumber = v.ViolationNumber,
                                    ViolationDate = v.ViolationDate,
                                    ViolationType = v.ViolationType.ViolationTypeCode,
                                    ItemYear = i.ItemYear,
                                    ItemMakeManufacturer = i.ItemMakeManufacturer,
                                    ItemModel = i.ItemModel,
                                    VIN = i.VIN,
                                    PIN = i.PIN,
                                    InspectionResultId = r.InspectionResultId,
                                    InspectionResultNumber = r.InspectionRequestNumber,
                                    DealerDmvNumber = r.DealerDmvNumber,
                                    InspectedCompanyName = (from a in contacts where a.ContactId == r.InspectedCompanyDataId select a.FirstName)?.FirstOrDefault()
                                }
                            ).ToList();
        

        At the line "InspectedCompanyName = (from a in contacts where a.ContactId == r.InspectedCompanyDataId select a.FirstName)?.FirstOrDefault()" I am getting following error - how can I get rid of it - thank you

        An expression tree lambda may not contain a null propagating operator

        Any help please

        B Offline
        B Offline
        Bohdan Stupak
        wrote on last edited by
        #3

        Just ditch question mark in front of FirstOrDefault.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups