C# error - "Not all code paths return a value" -


this simple method. use entity framework data , check values in if statement. right method marked red.

this method:

private bool issoleinproduction(long? shoelastid) {     if (shoelastid == null)     {         messagebox.show(resources.error_save,                          "error",                          messageboxbuttons.ok,                          messageboxicon.error);         return false;     }      isoleservice soleservice =          unitydependencyresolver.instance.getservice<isoleservice>();      list<sole> entity =          soleservice.all().where(s => s.shoelastid == shoelastid).tolist();      if (entity.count() != 0)     {         foreach (var items in entity)         {             if (items.status == 20)             {                 return true;             }             else             {                 return false;             }         }     }     else     {         return false;     }     } 

what missing?

you need take advantage of linq any, replace code:

if (entity.count() != 0) {     foreach (var items in entity)     {         if (items.status == 20)         {             return true;         }         else         {             return false;         }     } } else {     return false; }     

with simpler code:

 return entity.any(item => item.status == 20); 

or better performance:

 return soleservice.all()               .any(s => s.shoelastid == shoelastid                      && s.status == 20);  

edit: comment, below code need:

  list<sole> entity =  soleservice.all()                             .firstordefault(s => s.shoelastid == shoelastid);    return entity == null ? false : entity.status == 20; 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -