c# - Conditional shortcuts in LinqToSql query -


Here is a small LyncToSQL glow:

  // Provides the number of counties in the state Is, // or all the counties in the United States if the state is empty public stable intounts (state) {var q = from the seat in the county. GetTable (//) ITB to my method where (S == blank || S.Code == cy.StateCode) // Shortcut or operator, right ...? Select Cy; Return q.Count (); }  

What do you think - if you pass a null state by this method, then you get an empty reference exception! It seems that LinqToSql as a shortcut || does not use the shortcut operator!

Answer goes to anyone who gives the best explanation & amp; Solution for this

If this linq is sql, remember that linq is parsing your query in SQL .

So to send both of you to the clause where the database is, so the exception I really do not know this amazing, though it is logically incorrect

You only have to make an independent check.

  if (! String .isNullOrEmpty (state.statecode) q = q.where (s => code == state.statecode  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -