Id of newly added Entity before SaveChanges()
问题 I am adding an entity to my database like so: public TEntity Add(TEntity entity) { return (TEntity)_database.Set<TEntity>().Add(entity); } However, the DbSet.Add method isn't returning the newly added entity with the Id etc, it is simply returning the object I passed in to my Add method. Should it be passing me back the complete new entity including Id , or is it not possible to get the Id before SaveChanges() is called? 回答1: All the call to Add() is doing is effectively registering it with