vendredi 31 juillet 2015

Entity Framework SQL query on DateTime

I want to get 5 popular stories using Entity Framework query in a time span for example in 7 days or 14 days. I am storing views in a separate table with DateTime parameters with StoryID.

Stories table:

StoryID   Story
--------------------
1         story one
2         story two 
3         story three
4         story four
5         story five
6         story six

Views table:

ViewID     ViewDate             StoryID
---------------------------------------
  1        2015 07 17 19:00:00        1
  2        2015 07 17 20:00:00        1
  3        2015 07 17 21:00:00        2
  4        2015 07 18 19:00:00        2
  5        2015 07 19 19:00:00        2
  6        2015 07 21 19:00:00        1
  7        2015 07 23 19:00:00        2

Can you guys please help me figuring this out. Thanks

Edit: (so far this is what how I think I should do it)

return _viewdb.ObjectSet.Where(p => DateTime.Now >= EntityFunctions.AddDays(p.ViewDate, -14)).Select(p => new ExampleViewModel
            {
                StoryTitle = p.Sotries.Story,
            }).Take(5);

Aucun commentaire:

Enregistrer un commentaire