private Stat SaveChanges(MGFContext entities, DataEntities.Stat entity) { // Save everything in the context (unit of work means it should only be this entity and anything it contains) entities.SaveChanges(); // reload what the database has based on the ID that we modified return(Fetch(entity.StatId)); }
static void Main(string[] args) { using (MGFContext entities = new MGFContext()) { User user = new User() { LoginName = "admin" }; entities.Users.Add(user); entities.SaveChanges(); } }
protected override void DeleteNow(int id) { using (MGFContext entities = new MGFContext()) { MGF.DataEntities.Stat entity = new DataEntities.Stat { StatId = id }; // Gets the character list and attaches the entity to the contain (makes this object exist in the list of objects). entities.Stats.Attach(entity); // Remove the character from the container entities.Stats.Remove(entity); entities.SaveChanges(); } }