Create a DTO with all the properties you need except the image property:
public class YourDTO
{
public string YourProperty1 { get; set; }
public string YourProperty2 { get; set; }
// etc
}
You can then do:
var productDto = context.Products
.Where(x => x.Id == productId)
.Select(x => new YourDTO {
YourProperty1 = x.DbProperty1,
YourProperty2 = x.DbProperty2
// etc, don't include the image column
});
Update:
If you don't want to map the results to YourDTO
, you can project into an anonymous type:
var product = context.Products
.Where(x => x.Id == productId)
.Select(x => new {
x.DbProperty1,
x.DbProperty2
// etc, don't include the image column
});
...and if you want to provide a custom name for each of the properties of the anonymous type:
var product = context.Products
.Where(x => x.Id == productId)
.Select(x => new {
YourProperty1 = x.DbProperty1,
YourProperty2 = x.DbProperty2
// etc, don't include the image column
});
All of the above approaches would be functionally equivalent to the following SQL:
SELECT p.DbProperty1, p.DbProperty2
FROM products p
WHERE p.Id = WhateverId;