Tôi có một lớp như hình dưới đâyLàm thế nào để sắp đặt từng loại tài sản của ICollection <T> khi sử dụng Entity Framework
public class Survey
{
public Survey()
{
SurveyResponses=new List<SurveyResponse>();
}
[Key]
public Guid SurveyId { get; set; }
public string SurveyName { get; set; }
public string SurveyDescription { get; set; }
public virtual ICollection<Question> Questions { get; set; }
public virtual ICollection<SurveyResponse> SurveyResponses { get; set; }
}
Đoạn mã trên mang lại cho tôi sau ngoại lệ
Không thể serialize viên 'SurveyGenerator.Survey. Câu hỏi 'loại ' System.Collections.Generic.ICollection
Khi tôi chuyển đổi ICollection vào danh sách nó serializes đúng
Kể từ khi nó được POCO của Entity Framework, tôi có thể không chuyển đổi ICollection vào danh sách
Kiểm tra xem câu trả lời sẽ giúp bạn http: // stackoverflow.com/a/21660262/1488939 –
Điều gì xảy ra nếu bạn sử dụng Danh sách thay vì ICollection bằng Mã EF trước? Tôi đã bị ấn tượng vì nó vẫn hoạt động. –
CDeutsch