拉取數據時,我有,看起來像一個實體:Azure的移動客戶端掛起向特定對象
public class Category : EntityData
{
[Index("IX_CategoryName", IsUnique = true), MaxLength(60)]
public string Name { get; set; }
public string CreatorId { get; set; }
[ForeignKey("CreatorId"), JsonIgnore]
public User Creator { get; set; }
[JsonIgnore]
public virtual ICollection<Choice> Choices { get; set; }
[JsonIgnore]
public virtual ICollection<UserCategory> Users { get; set; }
public string Password { get; set; }
public bool Private { get; set; }
}
我遇到了一些問題,物業檢測自參照循環。我試了兩種(單獨和組合)
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
但沒有運氣。因此,我使用[JsonIgnore]標籤,就像您在我的實體中看到的一樣。就我所知,Azure移動服務甚至不會發送嵌套對象,所以沒有理由對其進行序列化。但是,當我嘗試拉取數據時,該過程永遠不會返回。沒有超時,沒有例外..
奇怪的部分現在來。如果我和郵遞員打電話給我,我會得到回覆。
{
"name": "Food",
"creatorId": "nemtid",
"password": null,
"private": false,
"id": "707cc064-f797-40ee-9ef1-b235e447ff5f",
"version": "AAAAAAAAB9k=",
"createdAt": "2016-11-29T19:58:12.58Z",
"updatedAt": "2016-11-29T19:58:12.58Z",
"deleted": false
}
所以我想這是一個客戶端的問題?..
我不知道我應該怎麼調試這一線索,所以如果你有任何線索,無論是如何調試這一點,或另一種解決自我引用循環問題的方法,請讓我知道。
編輯: 單方面的說明,使所有這一切更奇怪。 從我的客戶端,如果我拉所有的數據沒有問題(既沒有代碼掛起,也沒有自我引用問題,我用[JsonIgnore]固定。因此,我可以拉動所有數據就好了,沒有JsonIgnore)我的問題是與服務器上的此方法請求處理程序存在的:
public async Task<IEnumerable<Category>> GetSubscribedCategories(string userId, string subbedCats)
{
var res = _context.Categories.Where(c => c.Users.Select(u => u.UserId).Contains(userId));
return res;
}
這是一個實體框架問題比移動應用程序問題更多。編輯中的代碼實際上並不使用任何移動應用程序SDK的內容。建議您重新標記特定的實體框架受衆。 –
但問題是,當我調試服務器,我可以看到正確的數據,如果拉和返回。此外,如果我通過Postman手動發出請求,我也會得到正確的返回數據。這就是使這件事很難處理的原因。 – sirius
因此,您已經裁定服務器上的Azure移動應用程序代碼正在做正確的事情。您可以假設您正在從客戶端調用的服務器上的自定義API?你的代碼在這方面不完整,所以我只能假設。 –