Exemplo n.º 1
0
 private static void InsertNewMember()
 {
     using (var ctx = new SmartLibraryConsoleContext())
     {
         ctx.Memebers.Add(new Member {
             Name = "Atta Sammy"
         });
         ctx.SaveChanges();
     }
 }
Exemplo n.º 2
0
        //Always use the parent key in the child object other than saving the the updared member
        public static void InsertMemberObjectGraphNotTracked()
        {
            using (var ctx = new SmartLibraryConsoleContext())
            {
                var member = ctx.Memebers.First();

                var book = new Book {
                    Tilte = "Sam Jona", MemberId = member.Id
                };

                ctx.Books.Add(book);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 3
0
 private static void AddUnrelatedObjects()
 {
     using (var ctx = new SmartLibraryConsoleContext())
     {
         var m1 = new Member {
             Name = "Doe Boy"
         };
         var b1 = new Book {
             Tilte = "Lost Symbol"
         };
         ctx.AddRange(m1, b1);
         ctx.SaveChanges();
     }
 }
Exemplo n.º 4
0
        private static void AddRangeOfNewCustomers()
        {
            List <Member> members = new List <Member>
            {
                new Member {
                    Name = "Joseph"
                },
                new Member {
                    Name = "Thomas"
                },
                new Member {
                    Name = "Christian"
                }
            };

            using (var ctx = new SmartLibraryConsoleContext())
            {
                ctx.Memebers.AddRange(members);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public static void InsertMemberObjectGraph()
        {
            var member = new Member
            {
                Name  = "Zomi",
                Books = new List <Book>
                {
                    new Book  {
                        Tilte = "Adam slow"
                    },
                    new Book  {
                        Tilte = "John Brew"
                    },
                }
            };

            using (var ctx = new SmartLibraryConsoleContext())
            {
                ctx.Memebers.Add(member);
                ctx.SaveChanges();
            }
        }