This would work:
var trips = from t in ctx.Trips select new Trip
{
// db properties
t.ID,
t.Name,
t.Description,
// non-db properties
SomeValue = 45,
SomeOtherValue = GetValueFromSomewhereInCode(t.ID)
}
By projecting your database rows into 'new' Trip objects you can set properties that are not populated by LINQ to SQL, without any additional enumeration required. You can also call custom code in your projection because it executes in code, and not as part of the SQL statement sent to the database.
However, the resulting Trip objects are not enabled for change-tracking so bear that in mind (you can't make changes to properties and have them automatically updated via SubmitChanges()
, because the data context doesn't know about your Trip
objects).
If you need to track changes as well then you will need to enumerate the tracked Trip objects again after you have retrieved them via LINQ to SQL. This isn't really a problem though as it should be an in-memory iteration.