I want to insert a new entry into my database with the following commands:
Repository<Fueltype, TankeeContext> repository = new Repository<Fueltype, TankeeContext>();
Fueltype fuel = new Fueltype() {
Name = "Strom"
};
repository.Create(fuel);
That is the create- method of the repository
public void Create(T entity)
{
using (Ctx db = new Ctx())
{
db.Set<T>().Add(entity);
db.SaveChanges();
}
}
My problem is, that after inserting the entity Fueltype and calling the SaveChanges() method, the ID (IdFuelType) stays null, although it should be updated by the entity framework. My Entity Fueltype looks like that:
public partial class Fueltype
{
public Fueltype()
{
Gasprice = new HashSet<Gasprice>();
}
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int IdFuelType { get; set; }
public string Name { get; set; }
public ICollection<Gasprice> Gasprice { get; set; }
}