-2

I have this query below which works fine in LINQPad but it's giving me an error in my project

var query = from c in corps
            join cl in corpsPlaces on c.CorpID equals cl.CorpID into cl_join
            from cl in cl_join.DefaultIfEmpty()
            join l in places on cl.PlaceID equals l.PlaceID into l_join
            from l in l_join.DefaultIfEmpty()
            select new
            {
             c.CorpID,
             Name =  l.PlaceName == null ? c.CorpName : (l.PlaceName + " - " + c.CropName)
            };

I know I am using left join and name can be null therefore I used that conditional operator and the error line

 join l in places on cl.PlaceID equals l.PlaceID into l_join

I'm using EF 6, if it matters.

Any help will be appreciated

noɥʇʎԀʎzɐɹƆ
  • 9,967
  • 2
  • 50
  • 67
banker box
  • 137
  • 2
  • 3
  • 10
  • You need give us some background on your database so we can help you. And use grammar and spelling so people are more likely to answer. How to create a minimal, complete, verifiable example [mcve] – noɥʇʎԀʎzɐɹƆ Jun 27 '16 at 19:40
  • what part you didnt understand Grammatical Wise? – banker box Jun 27 '16 at 19:43
  • it's not a problem of understanding, but of quality. for example, you use "i" instead of "I". you also say "im using ef 6 if it matters" instead of "I'm using ef 6 if it matters". What's ef? – noɥʇʎԀʎzɐɹƆ Jun 27 '16 at 19:45
  • not to be a grammar nazi, just trying to get you more answers – noɥʇʎԀʎzɐɹƆ Jun 27 '16 at 19:45
  • ef is Entity Framework :D – banker box Jun 27 '16 at 19:46
  • We need you to get further in the problem-solving than just "I have a null reference". Please provide a good [mcve] that reliably reproduces the problem, as well as explain _specifically_ what is null, what you've done already to try to resolve the null reference, and what _specific_ difficulty you are still having in fixing the problem. – Peter Duniho Jun 28 '16 at 07:22

1 Answers1

0

You get a null reference exception for the cl.PlaceID in the second left join right? The reason in that cl is null and so cl.PlaceID results in a NullReferenceException.

You should use GroupJoin to perform so. Please look at this question

Community
  • 1
  • 1
Gilad Green
  • 36,708
  • 7
  • 61
  • 95