I am using MVC 6 rc1 with EF 7 rc 1 Code First Model to retrieve data via api web 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 the "Configure Services" section of Startup.cs.
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 api, I get an error, since "Chunked body does not end properly with size 0 size" in Fiddler. In the fiddler result set, I see only the first object of the expected result, set with properties, until the Categorizations are filled and there are no properties and the remaining objects after that (Incomplete JSON data). If I do not include Categorization in the result set, it works fine. Am I missing something? Note: EF returns data correctly, but it gets chunked in an api call, and the client cannot read the data completely.
source share