I'm currently creating an MVC / AngularJS application using EF database first method. After implementing my database, I realize that I cannot reference many-to-many relations, using the Database-First approach.
An example could be Table1
has a many-to-many relation to Table2
through a third table called Table3
. Table3
contains two primary keys: the PK of Table1
and the PK of Table2
. Updating my EDMX model, I still can't add this table, which makes sense, since it's jsut a many-to-many relation, and this property should be set on both the Table1
class model and the Table2
class.
Problem
Using AngularJS as my front end, I need to convert the data I'm retrieving from the database, and into the HttpResponse (IHttpActionResult
). I've had a problem like this before (using code-first) and simply disabled lazy loading (removed the virtual
keyword from the properties in my EMDX model classes).
After disabling lazy loading, I can't seem to include the relation. Here's an example of what I mean:
from t1 in _context.Table1.Include(x => x.Table2)
The Table2
reference simply isn't included, and therefore the Icollection<Table2>
is just null.
Does this even have anything to do with me removingthe virtual
keyword from my property, or is this something that's gone wrong with the mapping of the two?