Answers for "ef core linq"

C#
0

ef core linq

using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
 
namespace HelloApp
{
    public class Program
    {
        public static async Task Main(string[] args)
        {
            using (ApplicationContext db = new ApplicationContext())
            {
                var users = await db.Users
                                    .Include(p => p.Company)
                                    .Where(p => p.CompanyId == 1)
                                    .ToListAsync();     // асинхронное получение данных
 
                foreach (var user in users)
                    Console.WriteLine($"{user.Name} ({user.Age}) - {user.Company.Name}");
            }
            Console.Read();
        }
    }
}
Posted by: Guest on August-05-2021

C# Answers by Framework

Browse Popular Code Answers by Language