【发布时间】:2021-12-28 11:30:50
【问题描述】:
我创建了两个表:Claim 和 ClaimAttachments。 我正在尝试在 ClaimID 上加入它们,以便从两个表中获取过滤后的数据。
public ActionResult Index(int?search) {
if (search!=null)
{
var Product = (from P in db.Claims
join C in db.ClaimAttachments on
P.ClaimID equals C.ClaimID
select new Claim
{
ClaimID = P.ClaimID,
ClaimBatchID = P.ClaimBatchID,
PatientControlNumber = P.PatientControlNumber,
PatientFirstName = P.PatientFirstName,
PatientLastName = P.PatientLastName,
ServiceFromDate = P.ServiceFromDate,
ServiceToDate = P.ServiceToDate,
});
return View(db.Claims.Where(x => x.ClaimID == search).ToList());
}
else
{
return View(db.Claims.ToList());
}
我可以从单个表中获取搜索结果。连接不起作用。
【问题讨论】:
-
“不工作”究竟是什么方式?您观察到的实际问题是什么?
-
代替视图(db.Claims.Where(x => x.ClaimID == search).ToList());做查看(Product.Where(x => x.ClaimID == search).ToList());
-
@David,当我运行搜索过滤器时。结果仅显示在 Claims 表中,但我想要两个表的组合结果。
-
我做了 Product.Where(x => x.ClaimID == search).ToList());也是,但仍然没有从另一个表中获得过滤结果。
-
@CodeCademy:看起来您只是从一个表中选择:
db.Claims.Where(x => x.ClaimID == search).ToList()您希望看到其他表的哪些数据,为什么?即使在上面的代码行中,您也只能从Claims表中选择任何数据(然后永远不要使用该查询的结果)。您希望从哪个表中查看数据,为什么?当您在该查询中加入表时,您希望从这两个表中select 哪些数据? (目前您只能从 一个 表中进行选择。)
标签: c# xcode asp.net-mvc-5