Using the EF, a Rates table was created based on the Rate model below:
public class Rate
{
[Key]
public int IdNo { get; set; }
public string RateCode { get; set; }
public string RateClass { get; set; }
public string Basis { get; set; }
public bool RateIsActive { get; set; }
public DateTime? ValidFrom { get; set; }
public DateTime? ValidTo { get; set; }
public bool IsReservRate { get; set; }
public decimal? CostDay { get; set; }
public decimal? CostWeek { get; set; }
public decimal? CostMonth { get; set; }
public decimal? CostHour { get; set; }
}
I have no problem retrieving all columns from the Rates table using the code below:
using (AppDbContext db = new AppDbContext())
{
DbSqlQuery<Rate> data = db.Rates.SqlQuery("select * from Rates");
}
but what I need is to select only two columns from the table
DbSqlQuery<Rate> data = db.Rates.SqlQuery("select Rate, Class from Rates");
and it gives me the following error:
The data reader is incompatible with the specified 'RPManager.Models.Rate'. A member of the type, 'RateIsActive', does not have a corresponding column in the data reader with the same name.
Is there a way to active what is needed? NOTE!!!! I know how to do it using Linq but for this specific case it has to be done, if possible, using db.Rates.SqlQuery()