I need some help working with an IQueryable collection of data items and then selecting them into a new form.
The following method is called to get some data from a repository:
var data = this.repository.GetAllPersonalDetails();
I want to then convert each item in the collection to a business object which I do using the following:
var businessTypes = data.Select(dataType => new PersonalDetails
{
FirstName = dataType.FirstName
...etc.
});
This works fine and all is well, but the business object is quite big and I would like to make use of an adapter function that maps a data object to a business object. However, if I use code similar to the following:
var businessTypes = data.Select(dataType => this.ConvertToBusinessObject(dataType));
Then the whole Queryable pipeline gets messed up and I get exceptions when the query is eventually executed.
Does anyone know if what I'm trying to do is possible? It would be great if it was as we use adapter functions to convert between objects in a number of places and I'd rather re-use them instead of having to do the full conversion inline.