Entity Framework POCO Id not updated once SaveChanges is called


I’m using MongDB C# Entity Framework. Everything works fine, except, once I call SaveChange on the dbContext, my entity Id field is not updated… Se this simple example below:

public class Budget
    public ObjectId Id { get; set; }
    public string Name { get; set; }

public async Task Add(Budget entity)
    await db.Budgets.AddAsync(entity);
    await db.SaveChangesAsync();
    // entity.Id <=== Still equal 0x000000000000

Hi Reginald.

Support for auto-generated ObjectID’s has been checked in and will be available in the next preview release.

In the mean time you could set Id on the client via ObjectId.GenerateNewId() manually.