0

I want to add an object after the last row in table. But the object is randomly inserted anywhere in the table; sometimes at first, sometimes at middle; sometimes at last. I was sending an object from my frontend to web api.I generated the primary key by guid. It is GUID type. Before that it was string type. I am using code-first flow. Any help?

sanjidulhaque
  • 75
  • 2
  • 9

1 Answers1

2

I generated the primary key by guid.

Records are always maintained in the backing data by the clustered index. If you want the inserts to generally append at the end of the clustered index, use an IDENTITY integer primary key instead. (For SQL Server that is. Other database engines can use different keywords to define an incrementing integer PK.)

Additionally, when querying the data there is never a guaranteed sort unless you explicitly provide one. Any time you query your data and want a specific ordering, use an ORDER BY clause. (.OrderBy() in LINQ application code.)

David
  • 208,112
  • 36
  • 198
  • 279