ConvertToProjectors problem

Posts   
 
    
morten71
User
Posts: 82
Joined: 13-Jan-2009
# Posted on: 03-Apr-2010 19:27:31   

I'm trying to convert/project a collection to a datatable data structure like this:


Dim coll As New CollectionClasses.ActionsCollection
coll.GetMulti(selectFilter)
Dim v As New EntityView(Of ActionsEntity)(coll)
Dim dt As New Data.DataTable()
v.CreateProjection(EntityFields2.ConvertToProjectors(FactoryClasses.EntityFieldsFactory.CreateEntityFieldsObject(EntityType.ExportActionsEntity)), dt)

...however, I getting the following error:


Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityFields' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields2'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidCastException: Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityFields' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields2'.

Source Error: 


Line 105:   Dim v As New EntityView(Of ExportActionsEntity)(coll)
Line 106:   Dim returnValue2 As New Data.DataTable()
Line 107:   v.CreateProjection(EntityFields2.ConvertToProjectors(FactoryClasses.EntityFieldsFactory.CreateEntityFieldsObject(EntityType.ExportActionsEntity)), returnValue2)
Line 108:
Line 109:   Return returnValue2


Source File: C:\Visual Studio 2008\Projects\P1\App_Code\ActionHelper.vb Line: 107

Stack Trace: 

[InvalidCastException: Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityFields' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields2'.]
   ActionHelper.GetActionsAsDataTable(Int32 customerId, ActionSource actionSource, Int32 locationGroupId, ActionStatus actionStatus, Int32 countryId) in C:\Visual Studio 2008\Projects\P1\App_Code\ActionHelper.vb:107
   Common_UcActions.ExportActions_Click(Object sender, EventArgs e) in C:\Visual Studio 2008\Projects\P1\Common\UcActions.ascx.vb:298
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927 

What am I doing wrong?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Apr-2010 22:28:49   

Try this:

Dim coll As New CollectionClasses.ActionsCollection
coll.GetMulti(selectFilter)
Dim view As New EntityView(Of ActionsEntity)(coll)
Dim projResults As New Data.DataTable()

// create the projectors
List<IEntityPropertyProjector> projectors =
     EntityFields2.ConvertToProjectors(new ExportActionsEntityFactory().CreateFields());

// create the projection
view.CreateProjection(projectors, projResults)

David Elizondo | LLBLGen Support Team
morten71
User
Posts: 82
Joined: 13-Jan-2009
# Posted on: 05-Apr-2010 18:05:42   

Thanks for your help.

One strange thing. If I use EntityFields2.ConvertToProjectors I get the conversion error. If I use EntityFields.ConvertToProjectors it works.


Dim actions As New CollectionClasses.ExportActionsCollection
actions.GetMulti(selectFilter)
Dim view As New EntityView(Of ExportActionsEntity)(actions)
Dim projResults As New Data.DataTable()

' Works: EntityFields.ConvertToProjectors
Dim projectors As List(Of IEntityPropertyProjector) = EntityFields.ConvertToProjectors(New ExportActionsEntityFactory().CreateFields())

' Produces conversion error: EntityFields2.ConvertToProjectors
'Dim projectors As List(Of IEntityPropertyProjector) = EntityFields2.ConvertToProjectors(New ExportActionsEntityFactory().CreateFields())

view.CreateProjection(projectors, projResults)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Apr-2010 05:08:39   

My mistake, I forgot you were using SelfServicing. EntityFields2 y for Adapter, EntityFields is for SelfServicing. simple_smile

David Elizondo | LLBLGen Support Team