Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI have the latest version of Resharper, but this kind of LINQ query is outside of the scope of any refactoring options I can find. The null checks in this case are not to prevent null reference exceptions but to filter for values that exist or don't exist - therefore these can't be removed without changing the meaning of the clause. Unless it was to address a significant performance issue, I'm not sure that moving sections of the logic to the DB is a good idea as this adds additonal complexity and maintainance concerns. The key is to make the LINQ easy to read, understand, and test.
      singulars
    2. COIn your example `item.Status != null && item.Status != "Rejected"` does the same as `item.Status != "Rejected"` (in sql!). But you're right that where you really need to check for `IS NULL` this should also be coded in linq. As for computed columns and maintenance concerns: that depends on the development environment. I know projects where the database is kept as "dead" as possible (with valid reasons). In such a context I would not recommend computed column indeed. But in other projects we greatly benefit from them.
      singulars
    3. COTrue - that particular check could be simplified - that's the trouble with inventing examples ;) I guess that level of simplifcation is a good first step, but doesn't really address the wider requirement for a more readable and testable way to code complicated clauses. Isn't the computed column limited to the scope of the table? If so, it cannot handle any context data and so, other than in a possible performance variation I'm not sure how it's different from using a public property in c#. A property could be used to simplify the example slightly - but not to the same extent as object methods.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload