Problem fetching data from 2 tables

Posts   
 
    
TaLz
User
Posts: 12
Joined: 26-May-2009
# Posted on: 15-Sep-2009 09:32:14   

Hello, for some time now i have been using linq to lllblgen. recently i have come a cross a new problem. i have a grid that displays data from 2 tables. i want to be able to edit the grid and save the tables automatically. the 2 tables are related but one of them is a generic table and no constraint is defined on the datatable. for this reason i can't use "with path". it turns out you can't set the relation in runtime. it has to be declared in the database.

my nex try was to select the 2 entities and create a wrapper class but an exception was throw - cannot convert from system.int64 to the requested entity. example of the code:

LinqMetaData metaData = new LinqMetaData(new DataAccessAdapter());

        var query = from g in metaData.GnrlTransferAccount
                    join m in metaData.MsikMasikbekupa
                    on g.OwnerId equals m.MasikbekupaKod
                    select new TransferAccountDataRecord
                    {
                        MsikMasikbekupaEntity = m,
                        GnrlTransferAccountEntity = g
                    };

        return query.ToList<TransferAccountDataRecord>();

one last note. i want to get and save the data in the server. the ui has nothing to do with the database. the ui should get the list. not the query.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Sep-2009 13:06:25   

but an exception was throw - cannot convert from system.int64 to the requested entity.

Please post the equivilant stack trace.

TaLz
User
Posts: 12
Joined: 26-May-2009
# Posted on: 15-Sep-2009 14:58:55   

the exception: {"Unable to cast object of type 'System.Int64' to type 'Ness.ProvidentFunds.Common.DataAccess.EntityClasses.MsikMasikbekupaEntity'."}

source: "Anonymously Hosted DynamicMethods Assembly"

call stack:


   at lambda_method(ExecutionScope , Object[] , Int32[] )
   at SD.LLBLGen.Pro.LinqSupportClasses.DataProjectorToObjectList`1.AddRowToResults(IList projectors, Object[] rawProjectionResult)
   at SD.LLBLGen.Pro.LinqSupportClasses.DataProjectorToObjectList`1.SD.LLBLGen.Pro.ORMSupportClasses.IGeneralDataProjector.AddProjectionResultToContainer(List`1 valueProjectors, Object[] rawProjectionResult)
   at SD.LLBLGen.Pro.ORMSupportClasses.ProjectionUtils.FetchProjectionFromReader(List`1 valueProjectors, IGeneralDataProjector projector, IDataReader datasource, Int32 maxNumberOfItemsToReturn, Int32 pageNumber, Int32 pageSize, Boolean clientSideLimitation, Boolean clientSideDistinctFiltering, Boolean clientSidePaging, UniqueList`1 stringCache, Dictionary`2 typeConvertersToRun)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors, IGeneralDataProjector projector, IRetrievalQuery queryToExecute, Dictionary`2 typeConvertersToRun)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors, IGeneralDataProjector projector, IEntityFields2 fields, IRelationPredicateBucket filter, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteValueListProjection(QueryExpression toExecute)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.Execute()
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Ness.ProvidentFunds.Server.Fund.BusinessLogic.BusinessObjects.TransferAccountBO.GetTransferAccountCollection(Int32 trackID) in C:\Projects\ProvidentFunds\Fund\Fund.BusinessLogic\BusinessObjects\TransferAccountBO.cs:line 37
TaLz
User
Posts: 12
Joined: 26-May-2009
# Posted on: 15-Sep-2009 14:59:19   

h

TaLz
User
Posts: 12
Joined: 26-May-2009
# Posted on: 15-Sep-2009 14:59:31   

h

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Sep-2009 15:13:11   

select new TransferAccountDataRecord { **MsikMasikbekupaEntity **= m, **GnrlTransferAccountEntity **= g };

Are MsikMasikbekupaEntity and GnrlTransferAccountEntity properties of TransferAccountDataRecord? Anyway you can't do the assignment here, as m & g aren't materialized yet into objects of the corresponding entity classes.

Try to brake these into their primitve fields, like:

select new
{
  xyz = m.FirstName,
  abc = m.LastName,
  def = g.Amount
};
TaLz
User
Posts: 12
Joined: 26-May-2009
# Posted on: 16-Sep-2009 09:40:47   

[quotenick="Walaa"]

Try to brake these into their primitve fields, like:

i could do this. but how can i save the data after it is updated in the grid. i have to build the entities from the records some how.

does'nt llblgen support extracting data from 2 tables that don't have a relation defined in the database??

for example - table address. it can be for a company or a person. if i want a grid with the name of the person and his address and enable the user to update them. how can this be done?

address has 2 fields - ownerID and ownerTypeID

up until now i displayed data from a single table or tables with relations between them.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 16-Sep-2009 14:23:29   

does'nt llblgen support extracting data from 2 tables that don't have a relation defined in the database??

Yes LLBLGen can fetch fields from more than one table either with a relation defined in the database or define manually in code. But the question is in which structure should the data be fetched into.

What you need to do is to define the relation through the LLBLGen Pro Designer (Custom Relation). Then you will have the capability to use PrefetchPath (WithPath) to fetch the entities togther.