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()); } }
static void Main(string[] args) { using (var context = new EFCoreDemoContext()) { var genders = context.Gender.ToList(); } }
public void amendDataIntoDb(EFCoreDemoContext context, string FirstName) { var author = context.Authors.First(a => a.FirstName == FirstName); author.LastName = "Thakur"; context.SaveChanges(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var context = new EFCoreDemoContext(); DatabaseOperation dbo = new DatabaseOperation(); dbo.insertDataIntoDb(context); dbo.findDatafromDb(context, "Rabindranath"); dbo.findAllDatafromDb(context); dbo.amendDataIntoDb(context, "Rabindranath"); dbo.cancelDataIntoDb(context, "Rabindranath"); }
public void findAllDatafromDb(EFCoreDemoContext context) { var authorAndBookList = (from a in context.Authors join b in context.Books on a.AuthorId equals b.AuthorId select new { firstName = a.FirstName, book = b.Title }); foreach (var a in authorAndBookList) { Console.WriteLine("Author : " + a.firstName); Console.WriteLine("Book : " + a.book); } }
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(); }
public void cancelDataIntoDb(EFCoreDemoContext context, string FirstName) { context.Remove(context.Authors.Single(a => a.FirstName == FirstName)); context.SaveChanges(); }