I am working CodeFirst and I have the following table in my DB and when I want to show it the query in a DataGridView brings all fields, but I want to show only 2, exactly the name and the price. What should I modify in the Linq query?
var products = db.Products.Include(p => p.Category).OrderBy(p => p.Category.Name).ThenBy(p => p.Name);
dgvProductos.DataSource = products.ToList();
This is the class
public class Product
{
[Key]
[Column(Order = 0)]
public int ProductId { get; set; }
[Column(Order = 1)]
[Display(Name = "Categoría")]
public int CategoryId { get; set; }
[Column(Order = 2)]
[Display(Name = "Producto")]
public string Name { get; set; }
[Column(Order = 3)]
[DisplayFormat(DataFormatString = "{0:C2}", ApplyFormatInEditMode = false)]
[Display(Name = "Precio de alquiler")]
public decimal RentalPrice { get; set; }
[Column(Order = 4)]
[Display(Name = "Comentarios")]
public string Remarks { get; set; }
public virtual Category Category { get; set; }
}