How to specify few selected fields or column name in EF RRS feed

  • Question

  • User264732274 posted

    in below code we are binding product table data to gridview and all fields from the product table will be displayed but if i want to specify few fields or want to display specific 3 or 4 fields then how could i specify fields name in this line ctx.Products.ToList() ? please help me with code.

    using (var ctx = new NORTHWNDEntities())
          GridView1.DataSource = ctx.Products.ToList();

    Monday, April 6, 2015 2:32 PM


  • User2053451246 posted
    GridView1.DataSource = (from p in ctx.Products select new { p.Field1, p.Field3, p.Field3 }).ToList();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 6, 2015 2:56 PM