我目前正在开发一个庞大的项目,其中有列表模块,每个模块都有类库列表和一个调用所有模块的Web API项目。 我的意思是我的项目结构看起来像这样 -
-WebAPI (WebAPI project, which has reference to all Modules class libs)
-AccountManagementModule (Folder)
--AccountManagement.Repository (Class Library)
-GetAllProfileAndAddress (Method name inside a class Profile)
--AccountManagement.Test (Another Class Library for xunit test)
现在,当我从“AccountManagement.Test”项目调用“GetAllProfileAndAddress”方法时,我可以通过EF7的导航属性获取与该配置文件相关的个人资料和所有地址。
这是我的方法,它获取配置文件信息 -
public Profile GetProfile(Guid profileID)
{
var parent = uow.Repository<Profile>().Get(c => c.ProfileID == profileID);
}
但是,当我使用我的Web API控制器操作方法调用相同的方法时,导航属性没有加载。
我的意思是,当我从“AccountManagement.Test”项目调用方法“GetAllProfileAndAddress”时,我得到的结果低于结果
{
"Response": {
"Success": true
"Data": {
"ParentID": "18b96fa4-f6a5-4802-ba9e-bacba0b1500f"
"LastAppUseDate": "0001-01-01T00:00:00"
"Note": "This parent is associated with other students as well."
"ProfileID": "808b2d97-a5c6-4ef3-8899-9b0592ca3293"
"Address": <<Here I am getting the whole address object>>
}-
}-
}
但是,当我从“WebAPI”项目调用“GetAllProfileAndAddress”时,我收到了Address属性的NULL对象 -
{
"Response": {
"Success": true
"Data": {
"ParentID": "18b96fa4-f6a5-4802-ba9e-bacba0b1500f"
"LastAppUseDate": "0001-01-01T00:00:00"
"Note": "This parent is associated with other students as well."
"ProfileID": "808b2d97-a5c6-4ef3-8899-9b0592ca3293"
"Address": Null
}-
}-
}
我正在使用Visual Studio 2015,dnxcore50和Entity Framwork 7(7.0.0-rc1-final)。
有人可以告诉我为什么导航属性只有在从WebAPI项目调用时才为null?