문제

my Tables

Hotel

ID
Name

Price

PriceID HotelID
Price(decimal) StartDate

Discount

HotelID DiscountID DiscountType DiscountRate

The relationship Hotel and price 1 x n The relationship Hotel and discount 1 x n

but price can be Null and Discount can be null

var result = data.Hotels.GroupJoin(data.Prices, h => h.OtelID, p => p.OtelID, (h, p) => new { hotel = o, f = f.Where(x => x.StartDate<= Datetime.Now.date ).OrderBy(x => x.Price) })
                    .SelectMany(temp0 => temp0.f.DefaultIfEmpty(), (temp0, x) => new 
                    {
                        _hotel = temp0.hotel,
                        _Price = x,
                        _discount = ??
                    )});

how to write query? Single Hotel , Single ceaps price or NULL , Single Discount or Null

도움이 되었습니까?

해결책

var result = from h in data.Hotels
where true //where condition if any
select new 
{
_hotel = h,
_price = h.Prices.Where(p=>p).FirstOrDefault()//condition
_discount = h.Discounts.Where(true).FirstOrDefault() //condition
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top