相关疑难解决方法(0)

在WebAPI控制器中序列化EF Code First 5.0数据时出错

我最初问过这个问题: 如何解决"指定的包含路径无效"?已经回答了,而我的.Include()现在正在工作,但是,当序列化程序试图使它变得神奇时,我收到以下错误:

You must write an attribute 'type'='object' after writing the attribute 
with local name '__type'.
Run Code Online (Sandbox Code Playgroud)

这是我正在做的返回数据:

var everything = dc.Categories
            .Include(c => c.Products);
Run Code Online (Sandbox Code Playgroud)

我的类定义相当简单:

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; }
} …
Run Code Online (Sandbox Code Playgroud)

ef-code-first asp.net-web-api entity-framework-5

7
推荐指数
1
解决办法
6788
查看次数