2016-12-14 54 views
0

當嘗試選擇屬性作爲類時,出現問題。當我得到整個屬性(沒有$ select)時,它可以正常工作。

但是,如果我使用類屬性$ select,沒有錯誤,但該屬性不會返回。

GetByIds?$選擇=項目Id,匹克

摘不回來。只有ItemId。

public class ItemNotification : Entity 
{ 
    public ItemNotificationSetting Pick { get; set; } 
    public ItemNotificationSetting Receive { get; set; } 
    public string ItemId { get; set; } 
} 

public class ItemNotificationSetting 
{ 
    public bool IsEmail { get; set; } 

    public bool IsNotification { get; set; } 
} 

下面是我的建設者

modelBuilder.EntitySet<ItemNotification>("ItemNotifications"); 

感謝所有提前。

回答

1

Pick是導航屬性。你需要$expand吧。

GetByIds?$expand=Pick&$select=ItemId 

當我得到整體性能(無$選擇),它工作正常。

是否包含Pick即使您不要$expand呢?如果是這樣,讓我知道,因爲那麼可能有其他事情是錯的。默認情況下,不包括導航屬性。

+0

感謝您的快速回復,但** Pick **不是導航屬性。所以不能** **擴大**。你看,** Pick **在那裏沒有ID或鑰匙。 – Marcus

+0

@Marcus - 如果您根本不使用'$ select',結果中是否包含'Pick'? – smoksnes

+0

是的:)這是奇怪的事情。結果看起來像這樣{「ItemId」:「123」,「Pick」:{「IsEmail」:true,「IsNotification」:false}} – Marcus