public void Initialize(string agentName) { //find current agent in repository var agentRepo = _uow.Repository <TestAgent>(); _agent = agentRepo.Query().FirstOrDefault(z => z.Name == agentName); Debug.WriteLine("{1} TestAgent: {0}", agentName, _agent == null ? "Create" : "Update"); //create or update agent in repository if (_agent == null) { _agent = new TestAgent { Name = agentName }; agentRepo.Add(_agent); } _agent.Active(); _agent.LastTalked = DateTime.Now; _uow.Commit(); }