static void Main(string[] args) { // From 05 - 10 exercise are here! var context = new PhotographerContext(); Console.WriteLine(context.Photographers.Count()); //08.Tag attribute Tag tag = new Tag() { Label = "#Krushi" }; context.Tags.Add(tag); try { context.SaveChanges(); } catch (DbEntityValidationException e) { tag.Label = TagTransformer.Transform(tag.Label); context.SaveChanges(); } }
static void Main(string[] args) { var dbContext = new PhotographersDbContext(); Console.WriteLine(dbContext.Photographers.Count()); Tag tag = new Tag(); try { dbContext.SaveChanges(); } catch (Exception) { tag.Label = TagTransformer.Transform(tag.Label); dbContext.SaveChanges(); } }
private static void InsertSomeTag(PhotographersContext ctx) { Tag tag = new Tag(); Console.WriteLine("Give me some tag, please!"); tag.TagText = Console.ReadLine(); try { ctx.Tags.Add(tag); ctx.SaveChanges(); Console.WriteLine($"{tag.TagText} successfully added to database!"); } catch (DbEntityValidationException) { tag.TagText = TagTransformer.Transform(tag.TagText); ctx.SaveChanges(); Console.WriteLine($"{tag.TagText} successfully converted and added to database!"); } }