1

在我的播种机中,我执行以下操作,它们在数据库中的着陆顺序似乎不时不同!我需要顺序保持一致,因为我使用存储的静态变量来引用 ID。为什么顺序不同?我可以让它保持一致吗?谢谢你。

    List<BadgeGroup> BGs = new List<BadgeGroup>();
    BadgeGroup Unclassified = new BadgeGroup() { Description = "Unclassified" };
    BGs.Add(Unclassified);

    BadgeGroup NumVotesOnPost = new BadgeGroup() { Description = "Number of votes on a post" };
    BGs.Add(NumVotesOnPost);

foreach (BadgeGroup BG in BGs)
    db.BadgeGroups.AddOrUpdate(BG);
     db.SaveChanges();
4

1 回答 1

0

When you save a list of objects, EF doesn't guarantee that it'll be saved in that order. After you save, you can iterate through the objects to get their ids.

于 2013-02-24T03:41:51.917 回答