linq null refactoring code

Posted by user276640 on Stack Overflow See other posts from Stack Overflow or by user276640
Published on 2010-03-22T09:30:02Z Indexed on 2010/03/22 9:51 UTC
Read the original article Hit count: 358

Filed under:
|
|
|
|

i have code

public List<Files> List(int? menuId)
    {
        if (menuId == null)
        {
            return _dataContext.Files.ToList();
        }
        else
        {
            return _dataContext.Files.Where(f => f.Menu.MenuId == menuId).ToList();
        }
    }

is it possible to make it only one line like return _dataContext.Files.Where(f => f.Menu.MenuId == menuId).ToList();?

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about refactoring