In SQL Server, the Test database has a test table:

CREATE TABLE [dbo].[test]( [Key] [nvarchar](50) NULL, [Value] [nvarchar](100) NULL ) ON [PRIMARY] 

It is necessary with the help of EF Code First to output data from test to the DataGridView. There is no need to edit and save data in the database, just bring it to the control.
What is the minimum and sufficient code needed for this?

    1 answer 1

    To the WinForms project you need to connect the nuget-package EntityFramework .

     using System.Windows.Forms; using System.Linq; using System.Data.Entity; using System.ComponentModel.DataAnnotations.Schema; class Program { [STAThread] static void Main(string[] args) { var cs = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Test;"; var dc = new DbContext(cs); var dt = dc.Database.SqlQuery<Test>("select * from test"); var f = new Form(); var dg = new DataGridView() { Parent = f, Dock = DockStyle.Fill }; dg.DataSource = dt.ToList(); f.ShowDialog(); } class Test { public string Key { get; set; } public string Value { get; set; } } }