FetchEntity Error

Posts   
 
    
hommels
User
Posts: 23
Joined: 01-Jul-2005
# Posted on: 18-Jul-2005 18:09:20   

have been converting old self-servicing code to this Adapter code, and this code has an error. any idead/

The error says No entity factory specified in the passed in IEntityCollection2 object. Cannot continue

EntityCollection pc = new EntityCollection();

IRelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add( PredicateFactory.CompareValue( PersonFieldIndex.NetworkUsername, ComparisonOperator.Equal, Environment.UserName ) );

try { adapter.FetchEntityCollection(pc, filter);

                                    if ( pc.Count > 0 ) 
{
                                        return (PersonEntity)pc[0];
}

} catch ( Exception ex ) { Console.WriteLine( ex );

}

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Jul-2005 18:37:54   

this line: EntityCollection pc = new EntityCollection(); should be something like: EntityCollection pc = new EntityCollection(new PersonEntityFactory());

as in: you've to specify the factory for the entities which are to be loaded into the collection.

Frans Bouma | Lead developer LLBLGen Pro
hommels
User
Posts: 23
Joined: 01-Jul-2005
# Posted on: 18-Jul-2005 19:10:11   

I get an error on this code when I do the FetchEntityCollection An exception was caught during the execution of a retrieval query: The column prefix 'Enterprise.dbo.APP_USER_PREFERENCE' does not match with a table name or alias name used in the query. The column prefix 'Enterprise.dbo.APP_USER_PREFERENCE' does not match with a table name or alias name used in the query.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

Inner Exception Additional information: Object reference not set to an instance of an object.

private EntityCollection _AppUserPrefs = new EntityCollection(new AppUserEntityFactory()); IRelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add( PredicateFactory.CompareValue( AppUserPreferenceFieldIndex.AppId, ComparisonOperator.Equal, appId ) ); filter.PredicateExpression.AddWithAnd( PredicateFactory.CompareValue( AppUserPreferenceFieldIndex.PersonId, ComparisonOperator.Equal, personId ) );

try { adapter.FetchEntityCollection(_AppUserPrefs, filter); } catch(Exception ex) { Console.WriteLine(ex.InnerException.ToString()); }

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Jul-2005 19:22:33   

You're filtering on AppUserPreferenceEntity fields though are fetching AppUserEntity instances. Either add the relation AppUserPreference-AppUser to the filter.Relations collection or adjust your filters so you filter on AppUserEntity fields.

Frans Bouma | Lead developer LLBLGen Pro