How i can do LINQ Querie.
List<ApplicationUser> ListaUsuarios = AccountControl.UserManager.Users.Where(i => i.Nombre == Filter.Nombre).ToList();
With many Filters when some attributs can coming with Null Value. For example: My FilterGeneric Class have many Attribute accept Nulls.
public class FilterGeneric
{
public DataCollectionType.FiltrosPdf Tipo { get; set; }
public string PdfTitle { get; set; }
public string pdfDescription { get; set; }
public string Nombre { get; set; }
public string Cargo { get; set; }
public string Iniciales { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public bool? Enabled { get; set; }
public DateTime? Date_since { get; set; }
public DateTime? Date_to { get; set; }
public string RoleName { get; set; }
public string Id_Sucursal { get; set; }
public string RUC { get; set; }
public string Direccion { get; set; }
public int? Direccion_Nro { get; set; }
public string Telefono { get; set; }
public int? Id_Localidad { get; set; }
}
Is that Possible? Thanks all for listening.
UPDATE:
I test with Answers
1#:
if (Filter.Nombre != null)
{
query = query.Where(i => i.Nombre == Filter.Nombre);
}
2#:
List<ApplicationUser> ListaUsuarios = AccountControl.UserManager.Users.Where
(x =>
(x.Nombre == Filter.Nombre || string.IsNullOrEmpty(Filter.Nombre)) &&
(x.Nombre == Filter.Cargo || string.IsNullOrEmpty(Filter.Cargo)) &&
(x.Nombre == Filter.Iniciales || string.IsNullOrEmpty(Filter.Iniciales)) &&
(x.Nombre == Filter.UserName || string.IsNullOrEmpty(Filter.UserName))
).ToList();
I get this Error: