This is what my one of the repository classes looks like. Each repository class overrides this function.
Protected Overrides Function GetEntityType() As System.Type
Return GetType(Mail.DAL.EntityClasses.TblCostCentreEntity)
End Function
Protected ReadOnly Property CostCentreEntity() As EntityClasses.TblCostCentreEntity
Get
Return CType(MyBase.DataObject, EntityClasses.TblCostCentreEntity)
End Get
End Property
Then i use this in the Find function as described earlier.
the line in the find function where i doing meta.queryableforentity, datasource variable gets this value
SD.LLBLGen.Pro.LinqSupportClasses.DataSource(Of Mail.DAL.EntityClasses.TblCostCentreEntity) = {SD.LLBLGen.Pro.LinqSupportClasses.DataSource(Of Mail.DAL.EntityClasses.TblCostCentreEntity)}
and then i try to query and use the automapper to move it to the model class but then it throws the error as i attached before. If i don't use the automapper it returns the query fine but throws this error:
Unable to cast object of type 'SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery1[Mail.DAL.EntityClasses.EntityBase]' to type 'System.Linq.IQueryable
1[Mail.Model.CostCentreViewModel]'.
but i need to convert this to my model class? How else would i do that? Does the error i previously attached makes any sense to you? Please help. This is the main stage of my project, if i get it going, then everything else would flow on else i am stuck
--EDIT
It works this way but does not let me use my filter because it's of type ViewModel? Any workaround for this please?
Public Function FindS( _
Optional filter As Expressions.Expression(Of Func(Of T, Boolean)) = Nothing) As IEnumerable(Of T) Implements IRepository(Of T).FindS
Dim metaData As New LinqMetaData
Dim dataSource = TryCast(metaData.GetQueryableForEntity(CInt([Enum].Parse(GetType(EntityType), GetEntityType.Name))), IQueryable(Of EntityBase))
Dim q = (From p In dataSource _
Select p).ToList
Return AutoMapper.Mapper.Map(Of IEnumerable(Of T))(q)
End Function