locked
How do i convert this to get a list and not one item RRS feed

  • Question

  • User1034446946 posted

    at the moment I am doing something like

    _db.Where(m =>m.Title.Any(t => t.Text == "foo") && m.StartDate <= DateTime.Now && m.EndDate >=DateTime.Now).OrderByDesending(o => o.StartDate).FirstOrDefault();

    so I will have multiple records in the db with the title "foo" and I want to order them and get the most resent which is the one which has the importance, and it works

    However now i want to have a string array (or list or whatever of titles which I know I can have this

    _db.Where(m => m.Title.Any(t => stringArray.Contains(t.Text)) && m.StartDate <= DateTime.Now && m.EndDate >=DateTime.Now)

    but now I am a little stuck, I think I need to group by title, order the groups by date and then select the first onesfirst ones for each group, however I want to do this at datebase level as I don't want there return the Title Navigation entities, so selecting all the records and then running it i want to avoid.

    Does anyone have and suggestions?

    Thursday, June 14, 2018 12:25 AM

All replies

  • User1120430333 posted

    but now I am a little stuck, I think I need to group by title, order the groups by date and then select the first onesfirst ones for each group, however I want to do this at datebase level as I don't want there return the Title Navigation entities, so selecting all the records and then running it i want to avoid.

    The only ways that I know you can do this is use a stored procedure, inline raw T-SQL or Entity SQL with each option using a datareader and custom object like a DTO, if you're talking about doing something at the database level execution. 

    Thursday, June 14, 2018 2:06 AM