i have a table reservationbydate in that i have hotelid,type of room,date and noofroom.I should get the total no of rooms for aparticular date.
.how to return zero when output is null
var avaliabiltyQuery = from a in db.tbl_ReservationByDates
where a.HotelID == HotelId
&& a.RoomType == Drp_TypeOfRoom.Text
&& a.BookedDate == StartDate
group a by a.HotelID into g
select new {TotalRooms=g.Sum(a=>a.NoofBookedRooms)
var avaliabiltyQuery = from a in db.tbl_ReservationByDates
where a.HotelID == HotelId
&& a.RoomType == Drp_TypeOfRoom.Text
&& a.BookedDate == StartDate
group a by a.HotelID into g
select new {TotalRooms= (int?) g.Sum(a=>a.NoofBookedRooms) ?? 0
spriyanair
Member
19 Points
61 Posts
how to return zero when output is null
Nov 23, 2012 09:39 AM|LINK
Hi
i have a table reservationbydate in that i have hotelid,type of room,date and noofroom.I should get the total no of rooms for aparticular date.
.how to return zero when output is null
var avaliabiltyQuery = from a in db.tbl_ReservationByDates
where a.HotelID == HotelId
&& a.RoomType == Drp_TypeOfRoom.Text
&& a.BookedDate == StartDate
group a by a.HotelID into g
select new {TotalRooms=g.Sum(a=>a.NoofBookedRooms)
};
.
chaaraan
Contributor
2170 Points
484 Posts
Re: how to return zero when output is null
Nov 24, 2012 06:42 AM|LINK
Hi Priya
Check this
var avaliabiltyQuery = from a in db.tbl_ReservationByDates
where a.HotelID == HotelId
&& a.RoomType == Drp_TypeOfRoom.Text
&& a.BookedDate == StartDate
group a by a.HotelID into g
select new {TotalRooms= (int?) g.Sum(a=>a.NoofBookedRooms) ?? 0
};
Regards,
Charan
chetan.sarod...
All-Star
65719 Points
11133 Posts
Re: how to return zero when output is null
Nov 26, 2012 02:40 AM|LINK
Refer this
http://stackoverflow.com/questions/7586392/linq-query-null-exception-when-where-returns-0-rows
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.