Popular Datagridview with Entity Framwork

Asked

Viewed 174 times

0

  1. I have in SQL Server a database called STORE;
  2. In this database I have a table called Funcio, it contains 5 columns and they are respectively: Name, CPF, Date, Date issued, Idfuncionario.
  3. In my C# application I have already made the connection to the database through ADO.NET Model Entity Framwork and the model is called Lojaentities.
  4. I want to now popular datagridview1 with only 3 columns of the Funcionaio table, which would be respectively; Idfuncionaio, Nome, CPF.

What is the best way to make the village?

1 answer

0


Anyway, I did a little more digging and I think I’ve come up with a solution. What solves my problem is the so-called anonymous object, where we need to select more than one item of u

var db = new LojaEntities();
var consulta = from p in db.Funcionarios select new {p.Nome, p.CPF, p.Endereco};
datagridview1.DataSource = consulta.ToList();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.