Reputation: 4802
I am trying to return an IQueryable object in one of my functions and using mapping (Automapper). It manage to return an IEnumerable object fine but as soon as i try to return an IQueryable object it throws me an error:
This is the error:
Missing type map configuration or unsupported mapping.
Mapping types:
LLBLGenProQuery1 -> CostCentre
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery
1[[Mail.DAL.EntityClasses.TblCostCentreEntity, Mail.DAL, Version=1.0.4638.16064, Culture=neutral, PublicKeyToken=null]] -> Mail.Model.CostCentre
Destination path: CostCentre
Source value: SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1[Mail.DAL.EntityClasses.TblCostCentreEntity]
This is the code:
Dim metaData As New LinqMetaData Dim q = From p In metaData.TblCostCentre _ Select p Mapper.CreateMap(Of TblCostCentreEntity, CostCentre)()
Dim t As IEnumerable(Of CostCentre) = Mapper.Map(Of CostCentre)(q)
'Select New CostCentre With {.Active = p.Active, .CostCentre = p.CostCentre, .CreatedBy = p.CreatedBy, .DateCreated = p.DateCreated, .DateLastModified = p.DateLastModified, .ModifiedBy = p.ModifiedBy, .CostCentreID = p.CostCentreId}
Return t
Upvotes: 12
Views: 13502
Reputation: 1912
For anyone that might miss the comment link, you can use Automapper's [QueryableExtensions][1]
, specifically ProjectTo
. For example:
var collection = _db.Patients
.ProjectTo<PatientDto>(_mapper.ConfigurationProvider);
This will create an IQueryable projection from the db entity.
Upvotes: 7
Reputation: 6401
In order for Automapper to actually perform the mapping, it has to see each element in the IQueryable. Once you've iterated over a queryable, it is no longer queryable as it has been queried already.
Upvotes: 5