0

我需要在我的 LINQ To Entities 查询中将日期时间格式化为短日期字符串。我尝试了以下方法,但它不起作用 -

aryData =
(
    From cert In db.LWCerts _
    Select New With { _
       .ToBeProcessedDate = cert.ToBeProcessedDate.ToShortDateString 
    }
).ToArray()

我怎样才能得到一个日期作为短日期字符串(“ie:08/05/2013”​​)返回?

编辑这是整个 linq 查询-

             aryData =
        (From lwl In db.LWCertLoans _
        Join c In db.Loans _
   On c.LoanNum Equals lwl.LoanNum _
   Join p In db.LWCertColls _
   On lwl.CertID Equals p.CertID _
   Join r In db.RespCntrs _
   On r.BranchNum Equals c.BranchNum _
   Join cert In db.LWCerts.AsEnumerable() _
   On cert.LWCertID Equals lwl.CertID _
   Where lwl.LoanNum = p.LoanNum _
   Select New With { _
       .ToBeProcessedDate = cert.ToBeProcessedDate, _
    .CertType = cert.CertType, _
    .CertCollID = p.CertCollID, _
    .CertificateID = p.CertID, _
    .LoanNumberTypeAndCurrencyCombined = c.LoanNum, _
    .LoanType = c.LoanType, _
    .CurrType = r.CurrType, _
    .CollanteralBalance = c.ColCurBal, _
    .SalesAdditions = p.Sales, _
    .CreditMemos = p.Credits, _
    .CashRemovals = p.NetCollect, _
    .NonDilutiveAdjustment = p.PlusAdj, _
    .Discounts = p.Discounts, _
    .NonARCash = p.NonARCash, _
    .DilutiveAdjustment = p.NegAdj, _
    .LWCertCollsComments = p.Comments, _
    .StatusCode = p.StatusCode, _
    .CertLoanID = lwl.CertLoanID, _
    .Modified = lwl.Modified, _
    .LoanNum = lwl.LoanNum, _
    .EffectiveDate = lwl.EffectiveDate, _
    .RepWireNumber = lwl.RepWireNumber, _
    .Advance = lwl.Advance, _
    .ModifiedDate = lwl.ModifiedDate, _
    .DDAAccountName = lwl.DDAAccountName, _
    .LWCertLoansComments = lwl.Comments, _
    .Comment = If(cert.CertType = 0, p.Comments, lwl.Comments)}).ToArray()
4

1 回答 1

1

您应该使用以下命令将ToString数据库从数据库移动到应用程序AsEnumerable()

aryData =
(
    From cert In db.LWCerts.AsEnumerable() _
    Select New With { _
       .ToBeProcessedDate = cert.ToBeProcessedDate.ToShortDateString 
    }
).ToArray()

这将按DateTime原样从数据库中获取,然后在应用程序端对其进行格式化。

于 2013-08-05T15:49:29.250 回答