protected override Stat Update(Stat domainObject) { // Pull out the id because we'll be using it in a lambda that might be deferred when calling and the thread may not have access to the domain object's context // (yay multithreading) int id; if (null == domainObject) { throw new ArgumentNullException(nameof(domainObject)); } id = domainObject.Id; using (MGFContext entities = new MGFContext()) { DataEntities.Stat entity = entities.Stats .FirstOrDefault(statEntity => statEntity.StatId == id); if (entity != null) { Map(domainObject, entity); domainObject = SaveChanges(entities, entity); } } return(domainObject); }
public static IList <Stat> LoadStats(Character domainObject) { int id; List <Stat> stats; if (null == domainObject) { throw new ArgumentNullException(nameof(domainObject)); } id = domainObject.Id; stats = new List <Stat>(); using (MGFContext entities = new MGFContext()) { var query = entities.Stats .Where(statEntity => statEntity.CharacterId == id); foreach (DataEntities.Stat stat in query) { stats.Add(new Stat(stat.StatId, stat.Name, stat.Value)); } } return(stats); }
public static IList <Character> LoadCharacters(User domainObject) { int id; List <Character> characters; if (null == domainObject) { throw new ArgumentNullException(nameof(domainObject)); } id = domainObject.Id; characters = new List <Character>(); using (MGFContext entities = new MGFContext()) { var query = entities.Characters .Where(characterEntity => characterEntity.UserId == id); foreach (DataEntities.Character character in query) { characters.Add(new Character(character.Id, character.Name)); } } return(characters); }
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)); }
protected override Character Update(Character domainObject) { // Pull out the id because well be using it in the limbda that might be deferred when im calling and the thread may not have access to the domain objects context int id; if (null == domainObject) { throw new ArgumentNullException(nameof(domainObject)); } id = domainObject.Id; using (MGFContext entities = new MGFContext()) { DataEntities.Character entity = entities.Characters .Include(characterEntity => characterEntity.Stats) .FirstOrDefault(characterEntity => characterEntity.Id == id); if (entity != null) { Map(domainObject, entity); domainObject = SaveChanges(entities, entity); } } return(domainObject); }
protected override User Insert(User domainObject) { using (MGFContext entities = new MGFContext()) { DataEntities.User entity = new DataEntities.User(); Map(domainObject, entity); entities.Users.Add(entity); domainObject = SaveChanges(entities, entity); } return(domainObject); }
protected override Stat Insert(Stat domainObject) { using (MGFContext entities = new MGFContext()) { DataEntities.Stat entity = new DataEntities.Stat(); Map(domainObject, entity); entities.Stats.Add(entity); domainObject = SaveChanges(entities, entity); } return(domainObject); }
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(); } }
// Gets a list of all Characters in the database protected override IList <Character> Fetch() { using (MGFContext entities = new MGFContext()) { return(entities.Characters // Don't cash the entitiesin EF .AsNoTracking() // Order the entities by ID .OrderBy(characterEntity => characterEntity.Id) // Execute the querry and return a list .ToList() // Using the list of entities, create new DomainBase Characters .Select(characterEntity => new Character(characterEntity.Id, characterEntity.Name)) // Return a List<Character> of characters .ToList()); } }
protected override IList <Stat> Fetch() { using (MGFContext entities = new MGFContext()) { return(entities.Stats // Don't cash the entitiesin EF .AsNoTracking() // Order the entities by ID .OrderBy(statEntity => statEntity.StatId) // Execute the querry and return a list .ToList() // Using the list of entities, create new DomainBase Stat .Select(statEntity => new Stat(statEntity.StatId, statEntity.Name, statEntity.Value)) // Return a List<Stat> of stats .ToList()); } }
protected override User Fetch(int id) { User userObject = null; using (MGFContext entities = new MGFContext()) { DataEntities.User entity = entities.Users // Eagerly grab this entities linked object - Stats //.Include(characterEntity => characterEntity.Stats) .FirstOrDefault(userEntity => userEntity.Id == id); if (entity != null) { // Load data and extra data such as linked objects or XML data etc userObject = new User(entity.Id, entity.LoginName, entity.PasswordHash, entity.Salt); } } return(userObject); }
protected override Stat Fetch(int id) { Stat statObject = null; using (MGFContext entities = new MGFContext()) { DataEntities.Stat entity = entities.Stats // Eagerly grab this entities linked object - Stats //.Include(characterEntity => characterEntity.Stats) .FirstOrDefault(statEntity => statEntity.StatId == id); if (entity != null) { // Load data and extra data such as linked objects or XML data etc statObject = new Stat(entity.StatId, entity.Name, entity.Value); } } return(statObject); }
public static User LoadByUserName(string loginName) { User userObject = null; using (MGFContext entities = new MGFContext()) { DataEntities.User entity = entities.Users // Eagerly grab this entities linked object - Stats //.Include(characterEntity => characterEntity.Stats) .FirstOrDefault(userEntity => userEntity.LoginName == loginName); if (entity != null) { // Load data and extra data such as linked objects or XML data etc userObject = new User(entity.Id, entity.LoginName, entity.PasswordHash, entity.Salt); } } return(userObject); }
protected override Character Fetch(int id) { Character characterObject = null; using (MGFContext entities = new MGFContext()) { DataEntities.Character entity = entities.Characters // Eagerly grab this entities linked object - Stats //.Include(characterEntity => characterEntity.Stats) .FirstOrDefault(characterEntity => characterEntity.Id == id); if (entity != null) { // Load data and extra data such as linked objects or XML data etc characterObject = new Character(entity.Id, entity.Name); } } return(characterObject); }
public IList <Character> LoadByUserId(int userId) { using (MGFContext entities = new MGFContext()) { return(entities.Characters // Do not cache the entities in EF .AsNoTracking() // Order the entities by ID .OrderBy(characterEntity => characterEntity.Id) // Find all characters that match the provided userId .Where(characterEntity => characterEntity.UserId == userId) // Execute the query and return a list .ToList() // Using the list of entities, create new DomainBase Characters .Select(characterEntity => new Character( characterEntity.Id, characterEntity.Name)) // return a List<Character> of characters .ToList()); } }
// Gets a list of ALL Characters in the database protected override IList <User> Fetch() { using (MGFContext entities = new MGFContext()) { return(entities.Users // Do not cache the entities in EF .AsNoTracking() // Order the entities by ID .OrderBy(userEntity => userEntity.Id) // Execute the query and return a list .ToList() // Using the list of entities, create new DomainBase Characters .Select(userEntity => new User( userEntity.Id, userEntity.LoginName, userEntity.PasswordHash, userEntity.Salt)) // return a List<Character> of characters .ToList()); } }