### Define a BloggingContext and Entity Classes Source: https://learn.microsoft.com/ef/core This example demonstrates defining a DbContext class for database sessions and entity classes for Blogs and Posts. ```csharp using System.Collections.Generic; using Microsoft.EntityFrameworkCore; namespace Intro; public class BloggingContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer( @"Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;ConnectRetryCount=0"); } } public class Blog { public int BlogId { get; set; } public string Url { get; set; } public int Rating { get; set; } public List Posts { get; set; } } public class Post { public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public int BlogId { get; set; } public Blog Blog { get; set; } } ``` -------------------------------- ### Retrieve data with LINQ Source: https://learn.microsoft.com/ef/core Uses LINQ to filter and order entity instances from the database asynchronously. ```csharp using (var db = new BloggingContext()) { var blogs = await db.Blogs .Where(b => b.Rating > 3) .OrderBy(b => b.Url) .ToListAsync(); } ``` -------------------------------- ### Save data to the database Source: https://learn.microsoft.com/ef/core Adds a new entity instance to the context and persists the changes to the database. ```csharp using (var db = new BloggingContext()) { var blog = new Blog { Url = "http://sample.com" }; db.Blogs.Add(blog); await db.SaveChangesAsync(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.