private void DeleteEntity <TEntity>(TEntity entity) where TEntity : class { try { var efCodeFirstLibRepository = new EfCodeFirstLibRepository(); efCodeFirstLibRepository.DeleteEntity(entity); } catch (Exception exception) { var message = string.Format("Exception occurred attempting to delete 'entity' during a test. Error:{0}.", exception.ToString()); System.Diagnostics.Debug.WriteLine(message); } }
private static void RunCreateReadUpdateDeleteRepoExample() { var personSmith = new Person { FamilyName = "Smith", FirstName = "Pat", PetCount = 1 }; // Create 'Person' object to be added to database/repository. var efCodeFirstLibRepository = new EfCodeFirstLibRepository(); var createdPersonSmith = efCodeFirstLibRepository.PersonCreate(personSmith); // Insert new 'Person' record (from specified object values). var foundPersonSmith = efCodeFirstLibRepository.PersonFind(createdPersonSmith); // Find newly created 'Person' record (e.g. 'Identity/Primary Key' will have been incremented). var updatedPersonSmith = efCodeFirstLibRepository.DeepCloneViaJsonSerialization(foundPersonSmith); // Modify 'PetCount' property (incrementy by 10). updatedPersonSmith.PetCount = updatedPersonSmith.PetCount + 10; efCodeFirstLibRepository.PersonUpdate(foundPersonSmith, updatedPersonSmith); // Update 'Person' record (with increased 'PetCount'). efCodeFirstLibRepository.DeleteEntity(foundPersonSmith); // Remove/delete 'Person' record. }