static void Main(string[] args)
        {
            using (var context = new EFCoreDemoContext())
            {
                var author = new Author
                {
                    FirstName = "Neale",
                    LastName  = "Forrest",
                    Books     = new List <Book>
                    {
                        new Book {
                            Title = "One"
                        },
                        new Book {
                            Title = "Two"
                        },
                        new Book {
                            Title = "Three"
                        },
                    }
                };
                context.Add(author);
                context.SaveChanges();

                var data  = context.Books.Where(x => EF.Functions.Like(x.Title, "%e%"));
                var data2 = context.Books.Where(x => EF.Functions.);
                Console.WriteLine(data.Count());
            }
        }
Ejemplo n.º 2
0
    public void amendDataIntoDb(EFCoreDemoContext context, string FirstName)
    {
        var author = context.Authors.First(a => a.FirstName == FirstName);

        author.LastName = "Thakur";
        context.SaveChanges();
    }
Ejemplo n.º 3
0
    public void insertDataIntoDb(EFCoreDemoContext context)
    {
        var author1 = new Author {
            FirstName = "Stephen", LastName = "King"
        };
        var booksList1 = new List <Book> {
            new Book {
                Title = "It", Author = author1
            },
            new Book {
                Title = "Carrie", Author = author1
            },
            new Book {
                Title = "Misery", Author = author1
            }
        };

        var author2 = new Author {
            FirstName = "Rabindranath", LastName = "Tagore"
        };
        var booksList2 = new List <Book> {
            new Book {
                Title = "Gora", Author = author2
            },
            new Book {
                Title = "Chokher Bali", Author = author2
            },
            new Book {
                Title = "Gitanjali", Author = author2
            }
        };

        context.AddRange(booksList1);
        context.AddRange(booksList2);
        context.SaveChanges();
    }
Ejemplo n.º 4
0
 public void cancelDataIntoDb(EFCoreDemoContext context, string FirstName)
 {
     context.Remove(context.Authors.Single(a => a.FirstName == FirstName));
     context.SaveChanges();
 }