MVC EF 5 - How to reference Model FK Properties?
Hello, I'm having some trouble figuring out the logic to reference FK table properties from a model.
I'm currently using the same model for index and details views for an entity. On the index I have:
This displays the Species.Name corretly in the column (Dog/Cat/...), where Species is a FK in the Pet class (public virtual Species Species { get; set; }).
On the details view I have:
For the index on the controller I do:
However on the details I'm unable to use Include:
The error I get is:
I'm using repository pattern and dependency injection. So the GetByIdAsync() is implemented on a general repository for all entities.
While the GetByOwner() is specific to the Pets repository and returns a IQueryable<Pet>. Both repositories have the same references, tried to use .AsQueryable(), but have the same error. What am I doing wrong and how can I fix it?
Thanks in advance.
I'm currently using the same model for index and details views for an entity. On the index I have:
This displays the Species.Name corretly in the column (Dog/Cat/...), where Species is a FK in the Pet class (public virtual Species Species { get; set; }).
On the details view I have:
For the index on the controller I do:
However on the details I'm unable to use Include:
The error I get is:
I'm using repository pattern and dependency injection. So the GetByIdAsync() is implemented on a general repository for all entities.
While the GetByOwner() is specific to the Pets repository and returns a IQueryable<Pet>. Both repositories have the same references, tried to use .AsQueryable(), but have the same error. What am I doing wrong and how can I fix it?
Thanks in advance.