【发布时间】:2021-04-03 01:50:15
【问题描述】:
我想在工作站列表中包含已连接的设备。但我不仅得到了设备。我也得到了工作站。这是一种循环,没有必要。我怎样才能停止再次包含工作站,因为这也包含所有其他列表?
//returns to much
var workstations = this.context.TWorkstations
.Include(x => x.TDevices)
.AsQueryable();
//crash -> see error msg
var workstations = this.context.TWorkstations
.Include(x => x.TDevices).ThenInclude(d => d.Select(y => y.Alias))
.AsQueryable();
//crash -> see error msg
var workstations = this.context.TWorkstations
.Include(x => x.TDevices).ThenInclude(d => d.Alias))
.AsQueryable();
错误:
表达式“d.Alias”在“包含”操作中无效, 因为它不代表属性访问:'t => t.MyProperty'。到 在派生类型上声明的目标导航,使用强制转换 ('t => ((Derived)t).MyProperty') 或 'as' 运算符 ('t => (t as 派生).MyProperty')。集合导航访问可以通过过滤 组成 Where、OrderBy(Descending)、ThenBy(Descending)、Skip 或 Take 操作。有关包含相关数据的更多信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=746393.
[
{
"id": 102,
"workstation": "workstationName",
"comments": [],
"devices": [
{
"id": 93524,
"alias": "xxx",
"workstation": {
"id": 102,
"workstation": "workstationName",
【问题讨论】:
-
在
this.context里面有TDevices的东西吗?您的数据库结构如何?设备有自己的表吗?
标签: c# entity-framework linq entity-framework-core