Converting View Result to IEnumerable

Posts   
 
    
vivek
User
Posts: 45
Joined: 06-Sep-2012
# Posted on: 17-Oct-2012 03:12:28   

Hi Guys,

I am using LLBLGen Views in an MVC application and i need to return an IEnumerable object. My code looks like this:

Dim objExternalMailItemGroup As New TypedViewClasses.VwGetExternalMailItemTypedView Dim filter As IPredicateExpression = New PredicateExpression()

    filter.Add(New FieldCompareValuePredicate(VwGetExternalMailItemFields.StartDate, ComparisonOperator.LessEqual, StartDate))
    filter.AddWithAnd(New FieldCompareValuePredicate(VwGetExternalMailItemFields.EndDate, ComparisonOperator.GreaterEqual, EndDate))
    filter.AddWithOr(New FieldCompareNullPredicate(VwGetExternalMailItemFields.EndDate))

    objExternalMailItemGroup.Fill(0, Nothing, True, filter)

    Return AutoMapper.Mapper.Map(Of ExternalMailItemGroup)(objExternalMailItemGroup)

I was wondering if it's possible to return an IEnumerable object? whenever i try the following line, it does not work

Return AutoMapper.Mapper.Map(Of IEnumerable(of ExternalMailItemGroup))(objExternalMailItemGroup)

vivek
User
Posts: 45
Joined: 06-Sep-2012
# Posted on: 17-Oct-2012 04:00:53   

hmm Just got it working but want to verify that if i am on the right path.

to fix the issue what i have done is created a new mapping

    Mapper.CreateMap(Of TypedViewClasses.VwGetExternalMailItemRow, ExternalMailItemGroup)()

I previously only had the following mapping:

    Mapper.CreateMap(Of TypedViewClasses.VwGetExternalMailItemTypedView, ExternalMailItemGroup)()

and now it works!. Is this how it should be done? Do i need to create a mapping for viewitemrow object?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 17-Oct-2012 11:35:25   

(IMHO this is more an automapper question?)

Typedviews implement IEnumerable<T> where T is the type of the row object. I have no idea why automapper doesn't work with the call you made, as we're no experts on automapper, sorry.

Frans Bouma | Lead developer LLBLGen Pro