-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: select random records from a table
PostPosted: Mon Dec 19, 2005 4:21 pm 
Newbie

Joined: Wed Nov 02, 2005 9:52 am
Posts: 18
Location: Argentina
Hi! i need to do a sort of tests/evaluations (based on multiple-choice questions) that have a large number of records in the BD
The basic structure is:

Code:
Topics
->idTopic (int)
->Topic (string)

Questions
->idQuestion (int)
->Question (string)
->idTopic (int)

Answers
->idAnswer (int)
->Answer (string)
->valid (bool)
->idQuestion (int)


Imagine a one-to-many relationship between Topics-Questions and the same between Questions-Answers.

And i need to obtain a specified number of random Questions for each Topic, let`s say having 100 questions in the BD, display only 5 for each Topic, so each test will be diferent for each logged in user (ASP.NET) and each test is guaranteed to have 5 question of each topic. it's possible using NHibernate - HQL or somethig?

Thanks!!
Antares[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 9:11 am 
Newbie

Joined: Wed Nov 02, 2005 9:52 am
Posts: 18
Location: Argentina
it


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 1:08 am 
Newbie

Joined: Thu Nov 17, 2005 1:03 pm
Posts: 9
Location: Round Rock, TX
How was it soleved? I'm curious.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 9:19 am 
Newbie

Joined: Wed Nov 02, 2005 9:52 am
Posts: 18
Location: Argentina
Sorry my late post, not with NHibernate, simply using Random over an Ilist returned by a query
where:
lst is the full IList of items
list2 is the destination IList that function will return
and cant is the number of items to return

Code:
Dim x As Integer
Randomize()
Dim ran As New Random
.
.'get the items for list2
.
While list2.Count < cant
                x = ran.Next(lst.Count)
                list2.Add(lst.Item(x))
                lst.RemoveAt(x)
End While
Return list2


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.