One example, create a class that represents only properties you need.
public static async Task<CustomerItem> Example(int companyId)
{
await using var context = new Context();
return await context
.Customers
.Select(c => new CustomerItem()
{
CompanyName = c.CompanyName,
ContactId = c.ContactId,
CustomerIdentifier = c.CustomerIdentifier
}).FirstOrDefaultAsync(x => x.CustomerIdentifier == companyId);
}
Or perhaps using a projection where in the following example, data comes from Vendor model and returns a sub-set of type VendorListItem.
public class VendorListItem
{
public int Id { get; set; }
public string Name { get; set; }
public int NumberOfFruits { get; set; }
public static Expression<Func<Vendor, VendorListItem>> Projection
{
get
{
return x => new VendorListItem()
{
Id = x.Id,
Name = x.Name,
NumberOfFruits = x.Fruits.Count()
};
}
}
}