I am using MVC 6 rc1 with EF 7 rc 1 Code First Model to retrieve data over web api controller. I have 3 tables similar to below.
class Product
{
public int Id { get; set; }
public string SomeProperty { get; set; }
public virtual ICollection<Categorization> Categorizations { get; set; }
public DateTime SomeProperty2 { get; set; }
public string SomeProperty3 { get; set; }
public string SomeProperty4 { get; set; }
}
// NOTE: Entity key should be (ProductId, CategoryId)
class Categorization
{
public int ProductId { get; set; }
public Product Product { get; set; }
public int CategoryId { get; set; }
public Category Category { get; set; }
}
class Category
{
public int Id { get; set; }
public ICollection<Categorization> Categorizations { get; set; }
}
My Controller:
[ActionName("searchProducts")]
public IEnumerable<Product> searchProducts(string searchText,int? id)
{
var ret= db.Products
.Include(s => s.Categorizations).Take(2).ToList();
return ret;
}
Below is my Startup.cs ConfigureServices section.
services.AddMvc()
.AddJsonOptions(options=>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
});
services.AddCors();
var connectionString = Configuration.GetSection("Data:DefaultConnection:ConnectionString").Value;
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ContractsContext>(options => options.UseSqlServer(connectionString));
services.AddSingleton(_ => Configuration);
services.AddSingleton<IContractRepository, ContractRepository>();
When I call the api, I get the error as "Chunked body did not terminate properly with 0-sized chunk" in Fiddler. In fiddler resultset, I see only the first object of expected result set with properties until Categorizations filled and NO properties and remaining objects after that (Incomplete JSON data). If I do not include Categorizations in the result set, it works perfectly fine. Am I missing something? Note: EF is returning data correctly but it's getting chunked in the api call and client is unable to read the data in complete.