I have a database that is set up with lazy loading turned on(which is needed). I also have an ASP.NET MVC application that connects to the database and 'Does Stuff'. The database is modeled from my classes in a separate project.
I currently have 3 classes that use inheritance:
public class DeliveryNotification
{
[Key]
public int Id { get; set; }
public Status Status { get; set; }
}
.
public class TrackedDelivery : DeliveryNotification
{
[Required]
public DateTime Date { get; set; }
[Required]
public DateTime Time { get; set; }
}
.
public class SignedForDelivery : TrackedDelivery
{
[Required]
public string Image { get; set; }
}
These are all stored in the database using single table called 'DeliveryNotification'
I have been given a DeliveryNotification Id and would like to get all of the information.
Inside one of my controllers is this method:
var query = (from s in context.SignedForDeliverys
where s.Id == id
select s
).SingleOrDefault();
^ This will return null although there is a DeliveryNotification with the ID
var deliveryNotifications = context.DeliveryNotifications.SingleOrDefault(o => o.Id == id);
^ This will return only the id and the status.
So assuming I have been given an Id how can I return (preferably a SignedForDeliverys) with all of the data?
Edit: Tried to add an Include:
var signedForDeliverys = (from s in context.SignedForDeliverys.Include("TrackedDelivery ").Include("DeliveryNotification")
select s).ToList();
Then I get this error:
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: A specified Include path is not valid. The EntityType 'ClassLibrary.SignedForDelivery' does not declare a navigation property with the name 'TrackedDelivery'.