我正在构建一个网络核心堆栈并将这些层实现为异步。
我有以下客户存储库代码,由web api层调用
public class CustomerRepository : ICustomerRepository
{
//interface this up
private DbContextOptionsBuilder<SykesTestContext> optionsBuilder = new DbContextOptionsBuilder<SykesTestContext>();
public CustomerRepository(string connection)
{
optionsBuilder.UseSqlServer(connection);
}
public async Task<List<Dom.Customer>> GetAll()
{
List<Dom.Customer> customers = new List<Dom.Customer>();
var efCustomers = new List<Ef.Customer>();
using (var customerContext = new TestContext(optionsBuilder.Options))
{
efCustomers = await customerContext.Customer
.Include(cust => cust.Address)
.Include(cust => cust.Telephone)
.ToListAsync();
foreach (var customer in efCustomers)
{
customers.Add(Mapper.Map<Ef.Customer, Dom.Customer>(customer));
}
}
return customers;
}
}
API调用方法
[Produces("application/json")]
[Route("api/Customers")]
public class CustomersController : Controller
{
ICustomerRepository _customerRepository;
public CustomersController(ICustomerRepository customerRepository)
{
_customerRepository = customerRepository;
}
public async Task<List<Customer>> Get()
{
try
{
var customers = await _customerRepository.GetAll();
return customers;
}
catch (Exception ex)
{
throw ex;
}
}
}
如果我发表评论&#34;包括&#34;那一切都运转正常。
如果我使用includes(构建对象子集合),我在浏览器中遇到以下错误:net :: ERR_CONNECTION_RESET并且只返回部分json对象?
有什么想法吗?
public partial class Customer
{
public Customer()
{
Address = new HashSet<Address>();
Telephone = new HashSet<Telephone>();
}
public int Id { get; set; }
public int ClientId { get; set; }
public int TypeId { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public int? ExternalId { get; set; }
public virtual ICollection<Address> Address { get; set; }
public virtual ICollection<Telephone> Telephone { get; set; }
}
域模型
public class Customer
{
public int Id { get; set; }
public int ClientId { get; set; }
public int TypeId { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public int? ExternalId { get; set; }
public virtual ICollection<Address> Address { get; set; }
public virtual ICollection<Telephone> Telephone { get; set; }
}