Last post Jul 20, 2018 07:25 AM by Yuki Tao
Jul 19, 2018 07:21 AM|Serhat Ekici|LINK
I would like to list the information stored in the database so that only one row is coming up each time. db =new db.listdb.where(x=>Guid.NewGuid()).Take(1). I am using the query . each time the page is refreshed, a different record is coming. but after a
few refreshments, the old recordings are starting to appear. I need to write a query list so that old records are not listed after a record that I want to do is displayed.
Jul 19, 2018 07:32 AM|PatriceSc|LINK
Some details could help. If you never want to show the row again it could marked has being seen already. Or you could save the whole list (at least the pk). You have then a list in a random order that you can process sequentially so that each row is seen
one time only (at least until the list is exhausted).
This is a kind of ad rotator ?
Jul 19, 2018 07:42 AM|Serhat Ekici|LINK
I want to make sure that a different question is displayed each time a question is prepared for an exam I want to do. but I want to do this in a mixed way. I could do this partly with Guid.NewGuid. However, there is no idea how to write a code so that past
records are not listed. I'm sorry for my bad english.
Jul 19, 2018 08:17 AM|PatriceSc|LINK
The problem is that currently you create a random list each time and take the first element. So what you are doing is that you take just a single random element from a list each time with possible repetition.
Instead I would create a full random list once :
var studentQuestions=db.listdb.OrderBy(x=>Guid.NewGuid()).Take(10); // Take a single list of 10 random questions from the db.
I would then likey store this list to my db for this student (at least the pk) and I can then show this to the student that will have to answer to 10 unique questions
Jul 20, 2018 07:25 AM|Yuki Tao|LINK
Hi Serhat Ekici,
but after a few refreshments, the old recordings are starting to appear. I need to write a query list so that old records are not listed after a record that I want to do is displayed.
According to your requirement,I suggest you could filter the old records when 'only one row is coming up each time'.
And use First() to replace Take(1) so that get its properties easily.
Finally,use Where() to filter data.
Here my demo,you could refer to it:
var Currentdata= db.listdb.OrderBy(x => Guid.NewGuid()).First();
var Id = Currentdata.ID;
var List= list.Where(p => p.ID != Id); //delete the old data by Id
In addition,you should pay attention to the null,when the collection is getting less and less.