Jon*_*hal 1 c# navigation-properties entity-framework-core asp.net-core aspnetboilerplate
我正在AbpUser使用以下属性定义引用实体中的表:
[ForeignKey("LocationManagerId")]
public virtual User LocationManager { get; set; }
public virtual long LocationManagerId { get; protected set; }
Run Code Online (Sandbox Code Playgroud)
我的DTO如下:
[AutoMapFrom(typeof(Location))]
public class LocationDto : FullAuditedEntityDto<Guid>
{
// <snip>
public virtual User LocationManager { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
使用AsyncCrudAppService和从MVC控制器调用以下命令:
var locations = (await _locationAppService.GetAll(new PagedAndSortedResultRequestDto())).Items;
Run Code Online (Sandbox Code Playgroud)
locations.LocationManager正在返回null。我已经确认实体中的所有内容以及DTO都设置为virtual。我很茫然。有人有见识吗?
如果使用的是EntityFrameworkCore,则必须使用预先加载。
在以下方法中覆盖此方法LocationAppService:
protected override IQueryable<Location> CreateFilteredQuery(LocationGetAllInput input)
{
return Repository.GetAllIncluding(x => x.LocationManager);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
501 次 |
| 最近记录: |