/// <summary> /// Adding a new record to database via EF /// </summary> /// <param name="inputFileName"></param> /// <param name="inputFileContent"></param> /// <param name="outputFileName"></param> /// <param name="outputFileContent"></param> /// <param name="hashInput"></param> /// <param name="hashOutput"></param> /// <param name="trivia"></param> public static void AddNewRecord(string inputFileName, byte[] inputFileContent, string outputFileName, byte[] outputFileContent, string hashInput, string hashOutput, string trivia) { using (DESEDMEntities context = new DESEDMEntities()) { try { context.DESContents.AddObject(new DESContent() { InputFileName = inputFileName, InputFileContent = inputFileContent, OutputFileName = outputFileName, OutputFileContent = outputFileContent, HashInput = hashInput, HashOutput = hashOutput, Trivia = trivia }); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.InnerException.Message); } } }
/// <summary> /// Update a row via id /// </summary> private static void UpdateRecord() { using (DESEDMEntities context = new DESEDMEntities()) { EntityKey key = new EntityKey("DESEDMEntities.DESContents", "Id", 2222); DESContent contentToUpdate = (DESContent)context.GetObjectByKey(key); Console.WriteLine(contentToUpdate.EntityState); if (contentToUpdate != null) { contentToUpdate.InputFileName = "Updated.txt"; context.SaveChanges(); } } }
/// <summary> /// Remove a row via id /// </summary> public static void RemoveRecord() { using (DESEDMEntities context = new DESEDMEntities()) { EntityKey key = new EntityKey("DESEDMEntities.DESContents", "Id", 2222); DESContent contentToDelete = (DESContent)context.GetObjectByKey(key); if (contentToDelete != null) { context.DeleteObject(contentToDelete); context.SaveChanges(); } } }