Data Adapter

Posts   
 
    
Posts: 20
Joined: 27-Jun-2011
# Posted on: 29-Jun-2011 03:39:54   

Hi, I'm new to llblgen so this should be an easy question to answer

I have a method which takes a list of fields from one table with values. I just want to retrieve a list of rows which match the fields/values.

I'm using Data Adapter code not self servicing.

The query will only apply to one table, so I'm not interested in related entities at this stage.

Which data adapter function should I call?

Sorry I'm pretty confused.

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Jun-2011 05:44:28   

phil.salomon wrote:

I have a method which takes a list of fields from one table with values. I just want to retrieve a list of rows which match the fields/values.

How that list looks like? The best option is that you pass IEntityField2 objects.

Example:

public EntityCollection<CustomerEntity> SearchInCustomers(List<IEntityField2> fields, List<object> values)
{

     // build the filter
     IRelationPredicateBucket filter = new RelationPredicateBucket();
     for (int i=0; i< fields.Count; i++)
    {
        filter.PredicateExpression.Add(fields[i]  == values[i]);        
    }

    // fetch
    EntityCollection<CustomerEntity> customers = new EntityCollection<CustomerEntity>();
    using (var adapter = new DataAccessAdapter())
    {
          adapter.FetchEntityCollection(customer, filter);
    }

    // return results
    return customer
}

... and to use it:

IList<IEntityField2> theFields = new List<IEntityField2>();
IList theValues = new List();

theFields.Add(CustomerFields.CustomerId);
theValues.Add("ALFKI");

theField.Add(CustomerFields.Country);
theValues.Add("Guatemala");

// search
EntityCollection<CustomerEntity> matches = SearchInCustomers(theFields, theValues);

To know more about the predicate system and what else you can achieve, please read this.

David Elizondo | LLBLGen Support Team
Posts: 20
Joined: 27-Jun-2011
# Posted on: 29-Jun-2011 08:59:44   

Thanks. Got it working. I was using one of the overloads for FieldCompareValuePredicate where i was populating the second parameter which was a persistenceinfo. This was then stopping on a null value exception. I set the second parameter to null and now its working fine.