首页 > 解决方案 > 实体框架核心包括在存在相同值时全部为空

问题描述

我是 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; }

标签: asp.net-mvclinqmodel-view-controllerentity-framework-coreeager-loading

解决方案


推荐阅读