views:

70

answers:

1

When I run this code:

        korlenEntities2 _db = new korlenEntities2();
        for (int i = 0; i < 10; i++)
        {
            klienci klient = new klienci();
            klient.nazwa = "Janek_" + i.ToString();
            klient.miejscowosc = "-";
            _db.AddToklienci(klient);

        };
        _db.SaveChanges();

records are added to database in random order, so my field ID is not filled correctly. this is important to me since I want to use it for later ordering

+1  A: 

You cannot control the order of query execution unless you call SaveChanges after every query. Nor can you depend on auto-incremented keys to be sequential in all cases (consider replication). If order is important, you should add a field for that.

Craig Stuntz
He could also add a timestamp field if that is what he's looking for. He can sort later on the timestamp to get the insertion order.
David Pfeffer
But if value for timestamp will be generated on insert time by database the same problem will remain here, what's more I would need timestamp with precision to milliseconds.
Inez

related questions