asp.net-mvc - 实体框架核心包括在存在相同值时全部为空
问题描述
我是 EF Core 的新手,我有一个问题。我用Include()
方法列出了所有项目地址。它工作正常,但问题是当我具有相同的值(例如多个“洛杉矶”)时,只有最后一个地址所有者才能获得价值。其他变为空。为什么会发生?我很感激任何建议。
public List<AddressModel> GetAllDetailedAddresses()
{
return _projectContext.Addresses
.Include("City")
.Include("Town")
.Include("Neighbourhood")
.Include("Street")
.Where(q => !q.IsDeleted).ToList();
}
我有基本的 AddressModel :
//Table Properties
public int Id { get; set; }
public string LatLocation { get; set; }
public string LonLocation { get; set; }
public string FullAddress { get; set; }
//Relations
public int ProjectId { get; set; }
public ProjectModel Project { get; set; }
public int CityId { get; set; }
public CityModel City { get; set; }
//public ICollection<City> Cities { get; set; }
public int TownId { get; set; }
public TownModel Town { get; set; }
//public ICollection<Town> Towns { get; set; }
public int NeighbourhoodId { get; set; }
public NeighbourhoodModel Neighbourhood { get; set; }
//public ICollection<Neighbourhood> Neighbourhoods { get; set; }
public int StreetId { get; set; }
public StreetModel Street { get; set; }
//public ICollection<Street> Streets { get; set; }
//Table States
public bool IsDeleted { get; set; }
public DateTime CDate { get; set; } = DateTime.Now;
public DateTime? MDate { get; set; }
解决方案
推荐阅读
- sql - Postgres all_source 表等效
- c# - 在 C# 中将现有 XML 文件从 ANSI 编码标准转换为 UTF-8 编码标准
- react-native - 无法从模块 YYY 解析 XXX
- keras - keras:将图层添加到另一个模型
- c++ - 如何为数组分配多个值?
- ssl - 无法使用负载均衡器和 ssl 在 kubernetes (minikube) 上制作 vsftpd
- c++ - 为什么我的代码中出现分段错误?
- html - 智能手机上的网站通过键盘改变高度
- php - Enfold 4.7.6 Wordpress 主题 - 幻灯片放映(全角)包含分号“
- c# - 如何按属性对一组属性进行分组?