加入的附加条件
Additional conditions to join
查询中的第四行当前 return 多个 'RitsId'。我想从中 select 一个 'RitsId',通过添加以下两个条件。
需要按 'date' 和 'points'
过滤
- 其中 'points' 不等于 10(其中 rits.Points != 10)
- 从 rits table return 单条记录按最新 'date' 查询(例如:.OrderByDescending(rits => rits.RitsDate)
我可以知道如何在下面的查询中添加这些条件吗?我还是个初学者。谢谢。
var query = from ot in DbContext.tableOT
join rp in DbContext.tableRP on ot.OTId equals rp.OTId
join rits in DbContext.tableRITS on rp.RitsId equals rits.RitsId
// I get multiple RitsId as result in the below line, should add conditions to get a single RitsId of my choice
join ri in DbContext.tableRI on rits.RId equals ri.RId
where ri.ItemNo == itemno
select new pt()
{
...
}).FirstOrDefaultAsync();
return await query;
型号如下:
目标是从 tableOT 获得 'Description' 用于传入 'ItemNo'。
public partial class tableRI
{
public string ItemNo { get; set; }
public Guid RId { get; set; }
}
// I get multiple 'RitsId' for passed in 'RID', Need to add conditions to get single 'RitsId'
public partial class tableRITS
{
public Guid RitsId { get; set; }
public Guid RId { get; set; }
public DateTime RitsDate{ get; set; }
public int? Points { get; set; }
}
// By adding conditions, I can retrieve and pass the single RitsId of my choice below
public partial class tableRP
{
public Guid RitsId { get; set; }
public Guid? OTId { get; set; }
}
public partial class tableOT
{
public Guid? OTId { get; set; }
public string Description { get; set; }
}
尝试以下查询:
var query =
from ri in DbContext.tableRI
where ri.ItemNo == itemno
from rits in DbContext.tableRITS
.Where(rits => rits.Points != 10 && ri.RId == rits.RId)
.OrderByDescending(rits => RitsDate)
.Take(1)
join rp in DbContext.tableRP on rits.RitsId equals r.RitsId
join ot in DbContext.tableOT on rits.OTId equals ot.OTId
select new
{
// ... maybe other properties
ot.Description
};
return await query.FirstOrDefaultAsync();
查询中的第四行当前 return 多个 'RitsId'。我想从中 select 一个 'RitsId',通过添加以下两个条件。
需要按 'date' 和 'points'
过滤- 其中 'points' 不等于 10(其中 rits.Points != 10)
- 从 rits table return 单条记录按最新 'date' 查询(例如:.OrderByDescending(rits => rits.RitsDate)
我可以知道如何在下面的查询中添加这些条件吗?我还是个初学者。谢谢。
var query = from ot in DbContext.tableOT
join rp in DbContext.tableRP on ot.OTId equals rp.OTId
join rits in DbContext.tableRITS on rp.RitsId equals rits.RitsId
// I get multiple RitsId as result in the below line, should add conditions to get a single RitsId of my choice
join ri in DbContext.tableRI on rits.RId equals ri.RId
where ri.ItemNo == itemno
select new pt()
{
...
}).FirstOrDefaultAsync();
return await query;
型号如下:
目标是从 tableOT 获得 'Description' 用于传入 'ItemNo'。
public partial class tableRI
{
public string ItemNo { get; set; }
public Guid RId { get; set; }
}
// I get multiple 'RitsId' for passed in 'RID', Need to add conditions to get single 'RitsId'
public partial class tableRITS
{
public Guid RitsId { get; set; }
public Guid RId { get; set; }
public DateTime RitsDate{ get; set; }
public int? Points { get; set; }
}
// By adding conditions, I can retrieve and pass the single RitsId of my choice below
public partial class tableRP
{
public Guid RitsId { get; set; }
public Guid? OTId { get; set; }
}
public partial class tableOT
{
public Guid? OTId { get; set; }
public string Description { get; set; }
}
尝试以下查询:
var query =
from ri in DbContext.tableRI
where ri.ItemNo == itemno
from rits in DbContext.tableRITS
.Where(rits => rits.Points != 10 && ri.RId == rits.RId)
.OrderByDescending(rits => RitsDate)
.Take(1)
join rp in DbContext.tableRP on rits.RitsId equals r.RitsId
join ot in DbContext.tableOT on rits.OTId equals ot.OTId
select new
{
// ... maybe other properties
ot.Description
};
return await query.FirstOrDefaultAsync();