LINQ ~ example

今天張睪幫我寫的LINQ.......

我只能說太屌了XD

var blockItem = from b in context.Ap_LobbyBlocks
                            from bi in context.Ap_LobbyParts
                            where b.BlockID == bi.BlockID && bi.ShowOnLobby == true
                            select new BlockItem
                            {
                                key = bi.SkuID.ToString(),
                                imgSrc = bi.Ap_Skus.MainImg,
                                descName = bi.Ap_Skus.DescName,
                                price1 = (decimal)bi.Ap_Skus.Price1,
                                price2 = (decimal)bi.Ap_Skus.Price2,
                                b = bi.BlockID,
                                o = (from op in context.Ap_OptionSkus
                                     where op.SkuID == bi.SkuID
                                    select op.MenuOptionID).First()
                            };

            var block = from b in context.Ap_LobbyBlocks
                        select new Block
                        {
                            key = b.BlockID.ToString(),
                            title = b.Name,
                            items = (from bi in blockItem
                                      where b.BlockID == bi.b 
                                      select bi).ToArray()
                        }; 

沒有留言:

發佈留言