public static void CreateGameComment(GameCommentDTO gameCommentDTO) { // ballpark instance of Player class in Retrosheet_Persist.Retrosheet var gameComment = convertToEntity(gameCommentDTO); // entity data model //var dbCtx = new retrosheetDB(); var dbCtx = new retrosheetEntities(); dbCtx.Game_Comment.Add(gameComment); 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 Game_Comment convertToEntity(GameCommentDTO gameCommentDTO) { var gameComment = new Game_Comment(); gameComment.record_id = gameCommentDTO.RecordID; gameComment.game_id = gameCommentDTO.GameID; gameComment.inning = gameCommentDTO.Inning; gameComment.game_team_code = gameCommentDTO.GameTeamCode; gameComment.sequence = gameCommentDTO.Sequence; gameComment.comment_sequence = gameCommentDTO.CommentSequence; gameComment.comment = gameCommentDTO.Comment; return(gameComment); }
private static void ReadWriteGameCommentFile() { string[] columnValue; string textLine = null; using (StreamReader reader = new StreamReader(@"C:\users\mmr\documents\retrosheet\2016 Regular Season\Output\2016SLN\2016SLN_com")) { 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" + " file could not be read:"); Console.WriteLine(e.Message); Console.ReadLine(); } columnValue = textLine.Split('|'); GameCommentDTO gameCommentDTO = new GameCommentDTO(); gameCommentDTO.RecordID = Guid.NewGuid(); gameCommentDTO.GameID = columnValue[0]; gameCommentDTO.Inning = Convert.ToInt16(columnValue[1]); gameCommentDTO.GameTeamCode = Convert.ToInt16(columnValue[2]); gameCommentDTO.Sequence = Convert.ToInt16(columnValue[3]); gameCommentDTO.CommentSequence = Convert.ToInt16(columnValue[4]); gameCommentDTO.Comment = columnValue[6]; GameCommentPersist.CreateGameComment(gameCommentDTO); Console.WriteLine(textLine); } } }