У меня была эта проблема несколько дней назад, и я подумал, что нашел решение, которое устанавливает ленивую загрузку: false.но моя проблема с получением данных сохранилась.Используя fiddler или интерфейсное приложение, я не могу получить данные, и в результате у меня есть только такие значения, как: $ ref = 6 Я думаю, что это какая-то проблема общих настроек, поэтому я собираюсь дать некоторую информациюВот.
контроллер:
[AllowAnonymous]
[HttpGet]
[Route("GetQuestionsByTestId/{id}")]
public ICollection<Question> GetQuestionsByTestId(int id)
{
return db.Questions.Where(t => t.TestId == id)
.Include(a => a.Answers)
.Include(q=>q.Test)
.Include(q=>q.Test.TestType)
.ToList();
}
identityModels:
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
this.Configuration.LazyLoadingEnabled = false; //false for Lazy Loading Off
this.Configuration.ProxyCreationEnabled = false;
}
WebApiConfig:
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);
Модель вопроса:
[Table("Question")]
public class Question
{
public Question()
{
Answers = new HashSet<Answer>();
}
[Key]
public int QuestionId { get; set; }
[Required]
public string Name { get; set; }
public string Comment { get; set; }
public int Difficulty { get; set; }
public byte Repeat { get; set; } // 0 - 255
public bool IsLearned { get; set; }
public string QuestionNumber { get; set; }
public virtual ICollection<Answer> Answers { get; set; }
[ForeignKey("Chapter")]
public int ChapterId { get; set; }
public Chapter Chapter { get; set; }
[ForeignKey("Test")]
public int TestId { get; set; }
public Test Test { get; set; }
}
мой возврат получен с помощью chrome NETWORK: вот где моя проблема:
[{$id: "1", QuestionId: 5, Name: "11", Comment: null, Difficulty: 0, Repeat: 0,
IsLearned: false,…},…]
0: {$id: "1", QuestionId: 5, Name: "11", Comment: null, Difficulty: 0, Repeat: 0,
IsLearned: false,…}
1: {$ref: "6"}
второй объект не виден, есть только это: $ ref: "6"
Пожалуйста, помогите,потерять надежду здесь.