Problem with prefetch

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 09-Oct-2008 06:55:02   

I have this linq query:

var businesses = (from c in meta.Business
                                    join o in meta.FranchiseBusiness on c.BusinessId equals o.BusinessId
                                    where o.FranchiseId == businessId && c.IsActive == true && c.IsAcceptBooking == true
                                  select c).WithPath(p => p.Prefetch<BusinessCategoryEntity>(a => a.BusinessCategoryUsingBusinessCategoryId));

Which executes fine, except when I try and access businessEntityInstance.BusinessCategoryUsingBusinessCategoryId I get this exception:

Unable to cast object of type 'Shivam.TradeTerminal.DAL.EntityClasses.BusinessCategoryEntity' to type 'Shivam.TradeTerminal.DAL.EntityClasses.MyBusinessCategoryEntity'.

Line 924: public new virtual MyBusinessCategoryEntity BusinessCategoryUsingBusinessCategoryId Line 925: { Line 926: get { return (MyBusinessCategoryEntity)base.BusinessCategoryUsingBusinessCategoryId; } Line 927: set { base.BusinessCategoryUsingBusinessCategoryId = value; } Line 928: }

If I change my linq query to this:


var businesses = (from c in meta.Business.WithPath(p => p.Prefetch<BusinessCategoryEntity>(a => a.BusinessCategoryUsingBusinessCategoryId))
                                    join o in meta.FranchiseBusiness on c.BusinessId equals o.BusinessId
                                    where o.FranchiseId == businessId && c.IsActive == true && c.IsAcceptBooking == true
                                  select c);

(moved the withpath)

It fails to run and I get this:

Invalid column name 'F5_21'.


if (businesses.Count() > 0)
                {
                    BusinessList.Visible = true;
                    BusinessSearchResults.DataSource = businesses;
                    BusinessSearchResults.DataBind();//exception throws here
                }

Interestingly it gets passed the call to .Count(). I thought that would be where the query is executed...

and heres a big fat stack trace

[SqlException (0x80131904): Invalid column name 'F5_21'.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +925466 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800118 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932 System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31 System.Data.SqlClient.SqlDataReader.get_MetaData() +62 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +7 SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) +75

[ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: Invalid column name 'F5_21'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.] SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) +226 SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery) +147 SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) +897 SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) +115 SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteEntityProjection(QueryExpression toExecute) +193 SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) +177 SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression) +20 SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) +14 SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.IEnumerable.GetEnumerator() +13 System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +343 System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +53 System.Web.UI.WebControls.Repeater.DataBind() +72 Shivam.TradeTerminal.WebUI.Home.Franchise.BookJob.SearchBusinesses(Object sender, EventArgs e) in D:\Projects\Trade Terminal\Main\Source\Trade Terminal 1.0\WebUI\Home\Franchise\BookJob.aspx.cs:80 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

Can i get help with at least one of these problems please?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Oct-2008 07:28:30   

worldspawn wrote:

I have this linq query:

var businesses = (from c in meta.Business
                                    join o in meta.FranchiseBusiness on c.BusinessId equals o.BusinessId
                                    where o.FranchiseId == businessId && c.IsActive == true && c.IsAcceptBooking == true
                                  select c).WithPath(p => p.Prefetch<BusinessCategoryEntity>(a => a.BusinessCategoryUsingBusinessCategoryId));

Which executes fine, except when I try and access businessEntityInstance.BusinessCategoryUsingBusinessCategoryId I get this exception

Please post your LLBLGen RuntimeLibrary version. Or better, update to the latest build and try again.

Also, post the whole real code when you access the prefetched collection.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 09-Oct-2008 10:44:43   

(and please help us understand the exact entity structure: inheritance? Which hierarchy? You use 2-class scenario on adapter? If the problem is still in the latest build, please try a repro case with adventureworks, so we can reproduce it here)

Frans Bouma | Lead developer LLBLGen Pro
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 10-Oct-2008 01:05:58   

RuntimeBuild="09112008" RuntimeVersion="2.6.0.0"

I'm using adapter classes.

The FranchiseBusiness table references the Business and Franchise tables. Franchise also references the Business table (Franchise inherits from Business).

I'll see about creating a reproduction.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Oct-2008 07:04:40   

Waiting for you reproduction zip.

David Elizondo | LLBLGen Support Team