0

When adding elements to a newly created DbSet, are IDs always generated from 1 to (number of elements)... or do I have to add some code to make sure this happens...

The real problem is that I want to have

public DbSet<Student> Students { get; set; }
public DbSet<StudentPointer> top100allTime { get; set; }

so I have

public class StudentPointer
{
    public int StudentPointerID { get; set; }

    public int StudentID { get; set; }

    public int Votes { get; set; }
}

and

public class Student
{
    public int StudentPointerID { get; set; }

    public int StudentID { get; set; }

    public String name { get; set; }
}

so what happens here is that every time a user votes on a student I get the StudentPointer on top100allTime.. update its "Vote" variable... then assuming that "top100allTime" students are always in order of votes, I get the neighbor by its ID which is one number up, compare its votes, switch places in the top list if I have to.

This only works if IDs on dbSet always are generated in order from 1 to (number of elements)

that's why I am asking

or is there a more efficient way to make a top100List?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
porente
  • 371
  • 2
  • 14

1 Answers1

0

It will be a lot easier if you leave the 'votes' column inside the 'students' table and update it whenever someone votes for the student and then make an index on the 'votes' column and whenever you neet the top 100 you can 'select top 100 ordered by votes descending'. When your students table starts exceeding 500 000 records then you can use NoSQL db which will be enough for this job.

Ognyan Dimitrov
  • 6,026
  • 1
  • 48
  • 70
  • "whenever you neet the top 100 you can 'select top 100 ordered by votes descending". what if my main page is the top100list, does the database has to order the users again and again for every request it gets? – porente Dec 19 '14 at 18:51