Entity Framework - nested entites are null

asp.net asp.net-mvc c# entity-framework entity-framework-6

Popular Answer

FrameData, Card, Tags, DriverInfo are all one-to-one entites with TaskInfo:

You don't have to say, for instance, that TaskInfo has a DriverInfo object and that the DriverInfo object is associated with the TaskInfo object. Simply reference the other item in one object.

The other objects FrameData, Card, Tags, and DriverInfo have FKs for them that are PKs of TaskInfo.

public class TaskInfo
{
    public int TaskInfoId { get; set; }
    public int ExecId { get; set; }
    .../...
    public int DriverInfoId  { get; set; } // The PK of DriverInfo
    public virtual DriverInfo DriverInfo { get; set; }

}

Eliminate the mention of TaskInfo.

public class DriverInfo
{       
    public int DriverId { get; set; }
    public int DriverInfoId { get; set; }
}

FirstOrdefault would be preferable since it can handle a null return.

return context.Jobs.FirstOrDefault(job => job.JobId == id);
0
8/14/2017 10:16:13 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow