質問

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