Over the last few days I've been restructuring and existing application of mine written in C# to use Entity Framework instead of the custom data access layer I made. All was going well until I ran into a particular POCO.
This POCO has 6 properties, 4 of which are basic types, however the last 2 are giving me trouble because they are other existing POCOs. The reason this gives me trouble is because using Linq to Entity does not work correctly when trying to use Entity Framework to access my database.
Error given: "An error occurred while executing the command definition. See the inner exception for details." InnerException: "InnerException = {"Invalid column name 'Course_CourseId'.\r\nInvalid column name 'Student_StudentId'.\r\nInvalid column name 'Staff_StaffId'."}"
My Database structure is:
UniversityCatalog
Table: Courses
-Field: CourseId (Guid)
-Field: CourseName (String)
-Field: CourseNumber (String)
-Field: Comments (String)
-Field: CreditHours (int)
-Field: CourseTypeId (int) (ForeignKey: CourseTypes.CourseTypeId)
Table: CourseTypes
-Field: CourseTypeId (int)
-Field: CourseTypeName (String)
Table: Staffs
-Field: StaffId (Guid)
-Field: FirstName (String)
-Field: LastName (String)
-Field: EmployeeId (int)
Table: Students
-Field: StudentId (Guid)
-Field: FirstName (String)
-Field: LastName (String)
-Field: Grade (String)
Table: CourseOfferings
-Field: CourseOfferingId (Guid)
-Field: CourseId (Guid) (ForeignKey: Courses.CourseId)
-Field: StaffId (Guid) (ForeignKey: Staffs.StaffId)
-Field: Start Time (String)
-Field: End Time (String)
-Field: DayOfWeek (String)
Table: CourseRegistrations
-Field: CourseOfferingId (ForeignKey: CourseOfferings.CourseOfferingId)
-Field: StudentId (ForeignKey: Students.StudentId)
The POCO I have for the CourseOfferings Table is:
public class CourseOffering
{
public Guid CourseOfferingId { get; set; }
public String DayOfWeek { get; set; }
public String StartTime { get; set; }
public String EndTime { get; set; }
public Course Course { get; set; }
public Student Student { get; set; }
public Staff Staff { get; set; }
}
I suspect I'd have to do some custom mapping in my context file, however I have no idea what I'd be doing. Any tips or pointer would help me greatly! Thanks!
(Also here's my context file:)
class GatewayContext: DbContext
{
public DbSet<Course> Course { get; set; }
public DbSet<CourseType> CourseTypes { get; set; }
public DbSet<CourseOffering> CourseOfferings { get; set; }
public DbSet<Staff> Staff { get; set; }
public DbSet<Student> Students { get; set; }
}
Note: This is just a mock project to practice using these technologies