I am new in C# and have a quick question about the LINQ. I have a database which has two tables Re and De. The Re table has "Time" and "Id" columns. De table has "Id" and "data" columns. Now I want to get 5 entries from Re everyday and these 5 entries have to be randomly selected by time within that day. How can I do that. In addition, is there any kind of random number seed such that I can reproduce the randomness ? I tried couple of times, but it doesn't work.
Here is my code:
using (var db = new DBContext("Name=MyDB"))
{
var Query = db.Re.Join(db.De,
r => r.Id,
d => d.Id,
(r, d) => new { r, d })
.Where(cr => cr.r.Time >= new DateTime(2016, 1, 1)
&& cr.r.Time < new DateTime(2016, 1, 30))
.OrderByDescending(cr => cr.r.Id)
.GroupBy(a => new { y = a.r.Time.Year,
m = a.r.Time.Month,
d = a.r.Time.Day })
.SelectMany(g=>g.OrderBy(row => Guid.newGuid()).Take(200))
.Select(e => new
{
myId = e.r.Id,
mydata = e.d.data
})
.Take(100);
}