У меня есть поле даты «Fecha». Мне нужно отфильтровать мою таблицу, используя диапазон дат и это поле.
Это мой контроллер:
// GET: tb_visitas
public ActionResult Index(DateTime? startdate, DateTime? enddate)
{
var tb_visitas = db.tb_visitas.Include(t => t.tb_brochuras).Include(t => t.tb_despertai).Include(t => t.tb_estrangeiros).Include(t => t.tb_folhetos).Include(t => t.tb_livros).Include(t => t.tb_sentinela);
return View(tb_visitas.ToList());
}
Это моя Модель общедоступный частичный класс tb_visitas:
public int id_visita { get; set; }
[Required]
public int id { get; set; }
[Required]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime Fecha { get; set; }
public Nullable<int> id_g { get; set; }
public string videos { get; set; }
public Nullable<int> id_fol { get; set; }
public Nullable<int> id_livros { get; set; }
public Nullable<int> id_broc { get; set; }
public Nullable<int> id_wp { get; set; }
public string Relatorio { get; set; }
public virtual tb_brochuras tb_brochuras { get; set; }
public virtual tb_despertai tb_despertai { get; set; }
public virtual tb_estrangeiros tb_estrangeiros { get; set; }
public virtual tb_folhetos tb_folhetos { get; set; }
public virtual tb_livros tb_livros { get; set; }
public virtual tb_sentinela tb_sentinela { get; set; }
Почему вы не можете выполнить операцию Where с коллекцией?





Используйте метод LINQ .Where ().
// GET: tb_visitas
public ActionResult Index(DateTime? startdate, DateTime? enddate)
{
var tb_visitas = db.tb_visitas.Include(t => t.tb_brochuras)
.Include(t => t.tb_despertai)
.Include(t => t.tb_estrangeiros)
.Include(t => t.tb_folhetos)
.Include(t => t.tb_livros)
.Include(t => t.tb_sentinela)
.Where(t => t.Fecha >= startdate && t.Fecha <= enddate);
return View(tb_visitas.ToList());
}
https://docs.microsoft.com/en-us/dotnet/standard/using-linq
Работает! Спасибо! Как я могу сделать заказ через "Fecha", используя этот пример?
Простите! Как отфильтровать таблицу по диапазону дат? Пример: отфильтруйте записи с 01.03.2018 по 09.03.2018.