簡體   English   中英

更高效的Linq表達

[英]More efficient Linq expression

我有這個Linq加入

var NewQuote = (from qw in Q
                        join NW in NewNotes on qw.RECID equals NW.RECID into temp
                        from j in temp
                        select new Quotes
                        {
                            QuoteNumber = qw.QuoteNumber,
                            CustPartNumber = qw.CustPartNumber,
                            ITEMGROUPID = qw.ITEMGROUPID,
                          LotSize = qw.LotSize,
                          EAU = qw.EAU,
                          CONTACTPERSONID = qw.CONTACTPERSONID,
                          QUOTATIONSTATUS = qw.QUOTATIONSTATUS,
                          QUOTESENTDATE = qw.QUOTESENTDATE,
                          PricePerPiece = qw.PricePerPiece,
                          QuoteValue = qw.QuoteValue,
                          Email = qw.Email,
                          RECID = qw.RECID,
                          Notes = j == null ? "" : j.NOTES
                        }).ToList();

Q是Quote類的,但是我需要將數據從NewNotes添加到Notes字段中。 有比列出Quote類中的每個字段更好的方法嗎? 如果我必須在Quote中添加字段,那么我必須記錄該部分代碼並進行更新。

如果只想更新一個屬性,為什么要創建新的Quotes實例?

var query = from qw in Q join NW in NewNotes 
            on qw.RECID equals NW.RECID into temp 
            from j in temp
            select new { Quote = qw, Notes = j?.Notes ?? "" };

foreach(var x in query)
{
    x.Quote.Notes = x.Notes;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM