Introduction
In this blog we will see how to access existing sql server database with entity framework code first approach.
Step 1: Create console application

Choose code first from database

Program.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CFAUsingExsistingDB
- {
- class Program
- {
- static void Main(string[] args)
- {
- EmployeeContext objEmpContext = new EmployeeContext();
- foreach (var r in objEmpContext.Employees)
- {
- Console.WriteLine("FirstName: " + r.FirstName + " and " + "LastName: " + r.LastName);
- }
- Console.ReadKey();
- }
- }
- }
Output of the application looks like this

Summary
In this blog we have seen how we can access existing sql server database with entity framework code first approach. Happy coding.

Join the conversation! Your thoughts help the community grow.