Link to home
Start Free TrialLog in
Avatar of bmanmike39
bmanmike39

asked on

How do you select specific field from an entity like fNam lName and so on using entity?

I would like to select just specific fields in the db and create a list. I want the select statement to return all the records that have the InvoiceNumber of 1020.

and the only records in the field i want are fName, lName, and Email. This bind it to a dategrid.

How would I write this with entity.
MyEntities1 m = new MyEMEntities1();

int v = 1020;
GridView1.DataSource =  m.Invoice.fName,lName,Email(x => x.InvoiceNumber == v).ToList();
GridView1.DataBind();

Open in new window

Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi bmanmike39;

Try this, it should give you what you are looking for.

MyEntities1 m = new MyEMEntities1();

int v = 1020;

var results = m.Invoice
               .Where( i => i.InvoiceNumber == v)
               .Select( rec => new
               {
                   rec.fName,
                   rec.lName,
                   rec.Email
               }).ToList();

GridView1.DataSource = results;
GridView1.DataBind();

Open in new window

Avatar of bmanmike39
bmanmike39

ASKER

I get a error == can't be applied to type operand type 'sting' and 'int'
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!!
Not a problem bmanmike39, glad I was able to help.