我有以下模型:
public class Address
{
public int Id {get; set;}
public string Street1 {get; set;}
...
public int CountryId {get; set;}
public Country Country {get; set;}
}
public class Country
{
public int Id {get; set;}
public string Name {get; set;}
public string ISOCode {get; set;}
public string Continent {get; set;}
public string ISOCode {get; set;}
public string Languages {get; set;}
}
public class Church
{
public int Id {get; set;}
public string Name {get; set;}
public int CountryId {get; set;}
public Country Country {get; set;}
public int AddressId {get; set;}
public virtual Address Address {get; set;}
public string Phone {get; set;}
}
序列化程序是否认为我与 Country 存在某种双向关系,因为 Church 和 Address 都有 Country 对象?如果不是,那么为什么在尝试序列化教堂对象时会得到循环引用?
编辑: 让我更困惑的是,当我查询时,我什至不包括国家(在教堂):
var results = _context.Churches.Include(c => c.Address).Include(c => c.Address.Country).AsQueryable();
实体框架上下文已配置为未启用 LasyLoading。在我看来, Church.Country 应该为空,甚至不应该成为这里的问题。