【问题标题】:linq to sql outer left join with multiple join conditions [closed]具有多个连接条件的 linq to sql 外部左连接 [关闭]
【发布时间】:2012-07-24 22:55:55
【问题描述】:

我有一个需要连接并从中选择值的两个表,连接需要左外连接。我正在尝试使用 linq to sql 但得到 0 而不是实际值

参考表:

refType varchar(250),
description varchar(250)

presentationsType(我的另一个表)

id int
refType varchar(250),
OtherFundings varchar(250)

我使用的查询是

string organization = (string)Session["organization"];
int FiscalYear = Int32.Parse((string)Session["fiscalyear"]);
string ReportingPeriod = (string)Session["reportingperiod"];

var presentationType = from pt in OCHART.References
                       join rf in OCHART.OCHART_PresentationTypes on pt.RefType equals rf.RefType into prt                                       
                       from x in prt.Where(prt2 => prt2.OrganizationName.Equals(organization) && prt2.ReportingPeriod.Equals(ReportingPeriod) && prt2.FiscalYear == FiscalYear).DefaultIfEmpty()
                        where pt.RefType.Equals("09-10.1b")                                          
                        orderby pt.RefOrder ascending
                        select new {
                              refType = pt.RefType, 
                              refName = pt.Description,
                              otherFundings = (x.Fundings == null ? 0 : x.Fundings), 
                              id = (x.id == null ? 0 : x.id)
                         };

但我得到 id = 0 和 otherFunding = 0 尽管第二个表中有正确的值。我真的不确定自己做错了什么。

不胜感激。

谢谢。

【问题讨论】:

  • 我相信您可以将自己的问题标记为删除,因为它没有任何好处。

标签: c# asp.net linq-to-sql code-behind


【解决方案1】:

我很讨厌在长时间的脑筋急转弯之后提出一个问题,而不是自己找到解决方案。

请忽略这个问题,我的问题是没有链接正确的加入字段。

再次抱歉。

【讨论】:

  • 在这种情况下,也许可以分享您自己的答案。它可能对其他人有帮助:)
猜你喜欢
  • 2010-11-10
  • 1970-01-01
  • 2010-09-21
  • 1970-01-01
  • 2010-09-09
  • 2012-01-08
  • 2013-06-13
  • 1970-01-01
相关资源
最近更新 更多