2011-01-19 37 views
0

我有以下LINQ查詢返回一個報表對象;但我需要從另一列明確設置其中一個屬性的值。:如何返回帶有重寫值的輸入對象

Dim results As IQueryable(Of Report) 
results = From R In db.Reports _ 
     Join RS In db.ReportStatus On R.ReportID Equals RS.ReportID 
     Where RS.ActiveIndicator And _ 
      RS.StatusID <> clsCnst.Enum_ReportStatus.COMPLETE 
     Select R 

我想重寫R.LatestReportStatusDate = RS.StatusDate。我試着explciitly設置一個新的報告對象的屬性如下:

Dim results As IQueryable(Of Report) 
results = From R In db.Reports _ 
     Join RS In db.ReportStatus On R.ReportID Equals RS.ReportID 
     Where RS.ActiveIndicator And _ 
      RS.StatusID <> clsCnst.Enum_ReportStatus.COMPLETE 
     Select New Report With {.ReportID = R.ReportID, _ 
           .ReportTypeID = R.ReportTypeID, _ 
           .PatientID = R.PatientID, _ 
           .Locked = R.Locked, _ 
           .LockedDate = R.LockedDate, _ 
           .LatestReportStatusDate = RS.StatusDate} 

但是這會給我一個錯誤無法投類型的對象System.Data.Linq.DataQuery 1[VB$AnonymousType_6 14 .....到'System.Linq.IQueryable`1 [reportcirculation.Report]

我該如何解決這個問題?

回答

0

好找到了解決辦法,如果有人有興趣

Dim make As Func(Of Date, Report, Report) = Function(SD As Date, r As Report) 
               r.LatestReportStatusDate = SD 
               Return r 
              End Function 

results = From R In db.Reports _ 
      Join RS In db.ReportStatus On R.ReportID Equals RS.ReportID     
      Where RS.ActiveIndicator And _ 
       RS.StatusID <> clsCnst.Enum_ReportStatus.COMPLETE 
      Select make(RS.StatusDate, R)