I have a product
table. I want to get a specific column (only name and price columns) from this table, but I am getting an error. What am I doing wrong?
To summarize, I want to write
SELECT name, surname
FROM Product
WHERE name='emre'
but in my Entity Framework based code.
public class products
{
public int ID { get; set; }
public string name { get; set; }
public decimal price { get; set; }
public int stock { get; set; }
}
public class EtradeContext:DbContext
{
public DbSet<products> prdcts { get; set; }
}
My ProductDal.cs is below:
public List<products> GetNameAndPrice()
{
using (EtradeContext context = new EtradeContext())
{
var result = (from x in context.prdcts
where x.name == "emre"
select new products
{
name = x.name,
price=x.price
}).ToList();
return result;
}
}
And I am getting this error.