c# - Is this a DDD rule? -


ok have database-table 1000 rows.

from these need randomly extract 4 entries. business rule. random thing in linq or sql. domain project must independent, not referencing other project.

so should have list there, load 1000 rows , randomly extract 4 ddd-clean.

is ok? if db-table has 100k rows?

if primary keys sequential , not interrupted yield large performance benefits 100k or beyond tables. if not sequential believe can check , iterate lightly find it.

basically going want count of table

var rowcount = db.dbset<tablename>().count(); //ef pseudo  

and 4 random numbers in range

var rand = new random(); var randids = enumerable.range(0,4).select(i => rand.next(0,rowcount).array(); 

and iterate through getting records id (this done using contains , id, not sure faster 4 find should execute quickly).

var randomrecords = new list<tablename>(); foreach(int id in randids) {     var match = db.dbset<tablename>().find(id);     //if id not present, can iterate little find     //or provide custom column exact record indicate in comments     while(match != null)     {         match = db.dbset<tablename>().find(++id);     }     randomrecords.add(match); }  

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -