I have a problem with TPT inheritance + foreign key. I'm working on a web application with multi language support, including translating dynamic content. Here's my tables:
Language
=============
Id, Name
ProcessingAgent
====================
Id, some other fields
LocalizedProcessingAgent
=========================================================
LocalizedProcessingAgentId, Name, Description, LanguageId
As you already guessed, I moved the columns which should be translated from ProcessingAgent
to LocalizedProcessingAgent
. On EF side, I made a TPT inheritance, so ProcessingAgent
is a base class of LocalizedProcessingAgent
.
I'm new to EF, this i开发者_Go百科s my first project I moved on and one of it's strange behavior really confuses me.
When I generate EF classes from DB, LocalizedProcessingAgent
has a Navigation Property Language (Because of LanguageId
). The problem is that Language
property is null after I query the db:
LocalizedProcessingAgentRecord l = db.ProcessingAgents
.OfType<LocalizedProcessingAgentRecord>().First(p => p.Id == 1);
//l.Language is null
So the foreign key Navigation Property is not filled for some reason, I don't know why.
This happens only when I query derived entities, in this case LocalizedProcessingAgentRecord
.
Any ideas?
here's EF xml markup: http://dl.dropbox.com/u/3055964/ef.xml
You should explicitly load this Navigation property.
db.ProcessingAgents.Include("Language").OfType().First(p => p.Id == 1)
Include
will result in eager loading of navigation property.
精彩评论