本来我问过这个问题: 如何解决“A指定包含路径无效”? 这是回答了,我.INCLUDE()现在工作然而,当串行试图解决它的魔力,我得到以下错误:
You must write an attribute 'type'='object' after writing the attribute
with local name '__type'.
下面是我在做什么,返回的数据:
var everything = dc.Categories
.Include(c => c.Products);
我的类定义相当简单:
public class Category
{
public int CategoryId { get; set; }
public string Title { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
public class Product
{
public int ProductId { get; set; }
public string Title { get; set; }
public virtual Category Category { get; set; }
}
public class ProductDataContext : DbContext
{
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
}
我也试着删除“虚拟”,但后来我得到循环引用。 我试图使上ICollection的产品私人二传手(如下建议: http://forums.asp.net/t/1773164.aspx/1 ),其中获得误差清除,但后来我的产品都没有的部分返回的JSON。
我需要什么做的就是将数据与内部的类别及其产品序列?
编辑在这里是堆栈跟踪我得到:
[SerializationException: Object graph for type 'System.Collections.Generic.List`1[[Test.Models.Product, Test.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' contains cycles and cannot be serialized if reference tracking is disabled.]
System.Web.Http.WebHost.HttpControllerHandler.EndProcessRequest(IAsyncResult result) +30206
System.Web.Http.WebHost.HttpControllerHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +10
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9478661
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +178