public static void CreateEjection(EjectionDTO ejectionDTO) { // ballpark instance of Player class in Retrosheet_Persist.Retrosheet var ejection = convertToEntity(ejectionDTO); // entity data model //var dbCtx = new retrosheetDB(); var dbCtx = new retrosheetEntities(); dbCtx.Ejections.Add(ejection); try { dbCtx.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception e) { string text; text = e.Message; } }
private static Ejection convertToEntity(EjectionDTO ejectionDTO) { var ejection = new Ejection(); ejection.record_id = ejectionDTO.RecordID; ejection.game_id = ejectionDTO.GameID; ejection.inning = ejectionDTO.Inning; ejection.game_team_code = ejectionDTO.GameTeamCode; ejection.sequence = ejectionDTO.Sequence; ejection.comment_sequence = ejectionDTO.ComSequence; ejection.player_id = ejectionDTO.PlayerID; ejection.job_code = ejectionDTO.JobCode; ejection.umpire_id = ejectionDTO.UmpireID; ejection.reason = ejectionDTO.Reason; return(ejection); }
private static void ReadWriteEjectionFile() { string[] columnValue; string textLine = null; using (StreamReader reader = new StreamReader(@"C:\users\mmr\documents\retrosheet\2016 Regular Season\Output\2016SLN\2016SLN_com_ej")) { while (!reader.EndOfStream) { try { textLine = reader.ReadLine(); } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The " + @"C:\users\mmr\documents\retrosheet\2016 Regular Season\Output\2016SLN\2016SLN_com_ej" + " file could not be read:"); Console.WriteLine(e.Message); Console.ReadLine(); } columnValue = textLine.Split('|'); EjectionDTO ejectionDTO = new EjectionDTO(); ejectionDTO.RecordID = Guid.NewGuid(); ejectionDTO.GameID = columnValue[0]; ejectionDTO.Inning = Convert.ToInt16(columnValue[1]); ejectionDTO.GameTeamCode = Convert.ToInt16(columnValue[2]); ejectionDTO.Sequence = Convert.ToInt16(columnValue[3]); ejectionDTO.PlayerID = columnValue[6]; ejectionDTO.JobCode = columnValue[7]; ejectionDTO.UmpireID = columnValue[8]; ejectionDTO.Reason = columnValue[9]; EjectionPersist.CreateEjection(ejectionDTO); Console.WriteLine(textLine); } } }