Asp.net-mvc – Using Automapper to return IQueryable

asp.net-mvcautomapperllblgenprovb.net

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

Best Answer

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.

Related Topic