Ali Rezaii
Ali Rezaii

Reputation: 27

Combining several fields using Linq

I'd like to combine several table fields in order to produce a combined value.

Here's my code:

from _showtime in db.tbl_Concert_Showtime join _concerthall in db.tbl_Concert_ConcertHall on _showtime.ConcertHallID equals _concerthall.ConcertHallID
                 join _hall in db.tbl_Concert_Hall on _concerthall.HallID equals _hall.HallID
                 join _hallfloor in db.tbl_Concert_Hall_Floor on _hall.HallID equals _hallfloor.HallID
                 join _place in db.tbl_Concert_Hall_Floor_Place on _hallfloor.FloorID equals _place.FloorID
                 where _place.PlaceID == id
                 select _showtime

The showtime table includes the showID, startdate, starttime and endtime fields.

How can I select startdate and starttime in a field?

Something like this: 2015/12/12 12:25 -> 12:58

Upvotes: 0

Views: 35

Answers (1)

user761665
user761665

Reputation:

from _showtime in db.tbl_blablabla    
select _showtime.startdate + " " + _showtime.starttime + " -> " + _showtime.enddate

If you wanna Keep your original Showtime object but just add that combined value, do something like the follwoing:

from _showtime in db.tbl_blablabla    
select new 
{
    Showtime = _Showtime, 
    CombinedValue = _showtime.startdate + " " + _showtime.starttime + " -> " + _showtime.enddate
}

Upvotes: 3

Related Questions