I cannot run the query due to a strange error that occurs whenever I am trying to use "SELECT" construction
Error is:
The data reader is incompatible with the specified 'BDtest.Ticket'. The member of type 'Id' does not have a corresponding column of the same name in the data reader.
My model is:
public class Departure
{
public int Id { get; set; }
public string From { get; set; }
public string To { get; set; }
public bool Ended { get; set; }
public int MaximumTickets { get; set; }
public List<Ticket> Tickets { get; set; }
}
public class Ticket
{
public int Id { get; set; }
public string Passenger { get; set; }
public double Price { get; set; }
public string Type { get; set; }
public int DepartureId { get; set; }
public Departure Departure { get; set; }
}
The error query code:
var cross = ctx.Database.SqlQuery<Ticket>("SELECT Passenger FROM Tickets WHERE Id=5").ToList();
foreach (var item in cross)
{
richTextBox1.Text = item.ToString();
}
But this query is working:
var cross = ctx.Database.SqlQuery<Ticket>("SELECT * FROM Tickets WHERE Id=5").ToList();
I tried to do this, but it doesn't work either:
var cross = ctx.Database.SqlQuery("SELECT Passenger FROM dbo.Tickets WHERE Id=5").ToList();
Ticket? - Crowcoder