Bumped into a strange situation here. Trying to extract cars from a sql database within a certain range of a position (lat/long) and return an IQueryable to do additional logic on the resultset afterwards.
public IQueryable<Car> QueryAllCarsByDistance(float latitude, float longitude, int distance) { var cars = from car in QueryAllCars() join i in sqlContext.QueryContactsByDistance(latitude, longitude, distance) on car.ContactId equals i.Id orderby i.Distance select car; return cars; }
QueryContactByDistance beeing a function in the SQL database and QueryAllCars just returns all cars from database.
My question is now: How do I append the Distance (i.Distance) to car? I don’t want to do a select new Car { Distance = i.Distance, Id = car.Id, … }. But how to just append this additional value to the car object?
Unfortunately there is no way to do this. For most normal coding purposes, the type definitions emitted by C# and VB.Net are immutable. Fields and Properties cannot be added or removed from them at runtime.
All you can do is create a new type which wraps the Car type and provides the additional property. Or create an AnonymousType which has all of the properties needed.