I have a model class which looks like below:
public class ProductsViewModel
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public bool IsActive{ get; set; }
}
And bellow the Entity:
[Table("Products")]
public partial class Products
{
[Column("ProductId")]
public int ProductId { get; set; }
[Column("ProductName")]
public string ProductName{ get; set; }
[Column("IsActive")]
public bool IsActive { get; set; }
}
I'm fetching the result using the below LINQ query, which is returning correct data:
List<Products> productData = _context.Products
.Where(x => x.IsActive == true).ToList();
Now, I want to bind this data i.e productData with my model, something similar to ProductsViewModel = productData.
I know I can loop through productData records and assign values to model properties but I am looking for a direct way to map these two.
Is there any quick wat to get all the productData assigned to my model?
Selectmethod. It sounds like you have run through a basic Entity Framework tutorial and then stopped before getting to that stuff. I suggest you go back to it or find a better one :)