Skip to content

Lesson on working with EF Core 5 showing both beginner and advance operations with unit testing.

Notifications You must be signed in to change notification settings

karenpayneoregon/ef-core-lessons-csharp

Repository files navigation

About

immg

This repository is for teaching using Microsoft Entity Framework Core with a modified version of Microsoft NorthWind database.

First lesson walkthrough building the foundation for

  • Reading data with and without related data with EF Core and SQL-Server data provider
  • Using projections
  • Unit testing
  • Various DbContext configurations
  • Reverse Engineering a database using EF Power Tools
  • Source control, GitHub in Visual Studio

Sample test methods

namespace NorthWindCoreUnitTest
{
    [TestClass]
    public partial class CustomersTest : TestBase
    {
        [TestMethod]
        [TestTraits(Trait.EfCoreCustomersSelect)]
        public void CustomerCount()
        {
            using var context = new NorthwindContext();
            
            var customers = context.Customers.ToList();
            Assert.IsTrue(customers.Count == 91);
        }
        [TestMethod]
        [TestTraits(Trait.EfCoreCustomersSelect)]
        public async Task CustomersProject()
        {
            var customers = 
                await CustomersOperations.GetCustomersWithProjectionAsync();

            string firstName = customers
                .FirstOrDefault(cust => cust.FirstName == "Maria").FirstName;
            
            Assert.IsTrue(firstName == "Maria");
        }
    }
}

Future lessons

Will be done in branches in GitHub

Releases

No releases published

Packages

No packages published

Languages