Q:

LINQ introduce new field

I have the following
    var mylist= (from inlst in db.Progs
                 where inlst.ProgID == PGID
                 select new  
                 {
                   Date = inlst.Date1,
                   Name = inlst.Reps1,
                   Cancel = inlst.Cancel,
                   Reason = inlst.Reason,
                   Status = ... 
                 }).ToList();

I would like to introduce a new field not in the table called status 
that says:

if Date is not null then status = date else 
if Name is not null then status = name else 
if Cancel not null then status = reason else 
status = cancel

I am not sure how to introduce a new field though with if statement 

A:

You can do this with a simple Status = inlst.Date != null...
But i would make it a little more Typed like this. 
create a class
public class Prog
{
    public DateTime Date { get; set; }
    public string Name { get; set; }
    // ..

    public ProgStatus Status
    {
        get
        {
            if (Date != null)
                return ProgStatus.Date;
            if (Name != null)
                return ProgStatus.Name;
            // ..
        }
    }
}

create a enum of your possible status values
public enum ProgStatus {
    Name, Date // ...
}

then select it like this
var mylist = (from inlst in db.Progs
             where inlst.ProgID == PGID
             select new Prog 
             {
                Date = inlst.Date1,
                Name = inlst.Reps1,
                 // ..
             }

hope this helps

A:

Use short form of conditional operator :
Status = inlst.Date1 != null ? "Date" : inlst.Cancel != null ? "Cancel" : ... : string.Empty;

