better way to code this linq statement -


im looking advice on better way code below in linq?

var tblequipments = d in db.tblequipments.include(t => t.user).include(t => t.changelog).asenumerable()                             ((d.development != 1 || d.development == null) &&             (d.deleted != 1 || d.deleted== null ) &&             (d.stock != 1 || d.stock == null)) &&             (d.decommissiondate == convert.todatetime("1900-01-01") || d.decommissiondate == null)  select d; 

thanks

some suggestions:

  1. don't .asenumerable unless absolutely necessary cause filtering done client side rather in database (where want it).
  2. evaluate constants outside of linq. (for example doing convert.todatetime each row evaluating (every row in tblequipments issue 1 above).
  3. assuming development, deleted, stock , decommissiondate nullable, try .getvalueordefault(0) rather value != 1 || value == null. (note, dependant upon orm provider supporting construct , fix #1 above.
  4. do nullability tests before comparison, otherwise code may fail @ runtime when trying compare null value.

Comments

Popular posts from this blog

javascript - JS causing window size to be bigger than necessary - Dropdown bug -

How to mention the localhost in android -

php - Calling a template part from a post -