A more complex LINQ statement

Source: Internet
Author: User

As a beginner, it took me a lot of effort to write this sentence. It is secondary to write it out. What is important is that I learned a new usage.

VaR query = from GB in objectcontext. goodsclose_back
Where GB. s_sf = comid & GB. s_month = month
Join GW in // subquery similar
(
From GHB in objectcontext. goodsclose_history_caiwu_1
Where GHB. s_month = lastmonth
Join W in objectcontext. waitfinancein_import

 

// Match the new {GHB. s_goodsid, GHB. s_sf, s_month = month} combinations. The names of the fields before and after the match must be the same.
On New {GHB. s_goodsid, GHB. s_sf, s_month = month} equals New {W. s_goodsid, W. s_sf, s_month = W. s_month} into T // left join. If defaultifempty () is not used here, it is equivalent to the number of rows on the right of the data on the left, which exist as a set, when this function is used, the data on the right is split up several times to repeat the data on the left to correspond to the data on the right.
Select New // goodsclosefinancebackpm
{

 

// Here s_goodsid, s_sf, and s_month are used for the following purposes. If this parameter is not set, it will not be called below.
S_goodsid = GHB. s_goodsid,
S_sf = GHB. s_sf,
S_month = month,
Currentwaitinqty = T. sum (x => (X. f_importqty ?? 0)-(X. f_inv_qty ?? 0 )),
Currentwaitinamt = T. sum (x => (X. f_importqty ?? 0) * (X. f_importpri ?? 0)-(X. f_inv_qty ?? 0) * (X. f_importpri ?? 0 )),
Oldcloseqty = GHB. f_closeqty ?? 0,
Oldcloseamt = GHB. f_closeamt ?? 0,
Oldpri = GHB. f_closepri ?? 0,
Oldwaitinqty = GHB. f_current_waitfinanceinqty ?? 0,
Oldwaitinamt = GHB. f_current_waitfinanceinamt ?? 0
}
) On new {GB. s_goodsid, GB. s_sf, GB. s_month} equals New {GW. s_goodsid, GW. s_sf, GW. s_month} into GWT
From GW in GWT. defaultifempty ()
Select New goodsclosefinancebackpm
{
Goodsid = GB. s_goodsid,
Comid = comid,
Month = month,

Closeqty = GB. f_closeqty ?? 0,
Purpri = GB. f_purpri ?? 0,
Inqty = GB. f_inqty ?? 0,
Outqty = GB. f_outqty ?? 0,
Transeinqty = GB. f_transinqty ?? 0,
Transeoutqty = GB. f_transoutqty ?? 0,
Unit = GB. s_unit,
Oldpri = GW. oldpri,
Currentwaitinqty = GW. currentwaitinqty,
Currentwaitinamt = GW. currentwaitinamt,
Oldcloseqty = GW. oldcloseqty,
Oldcloseamt = GW. oldcloseamt,
Oldwaitinqty = GW. oldwaitinqty,
Oldwaitinamt = GW. oldwaitinamt
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.