Print Page | Close Window

Question on converting EntityList to List

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=209
Printed Date: 29-Aug-2025 at 6:36pm


Topic: Question on converting EntityList to List
Posted By: Customer
Subject: Question on converting EntityList to List
Date Posted: 12-Jul-2007 at 3:43pm

I would just like to ask if converting from System.Collections.IList to IdeaBlade.Persistence.EntityList? Because I’m having problems when filtering records using the FindAll method of Entitylist that returns an IList object. Is it possible to return an EntityList object instead of the IList??

 

Here is the method where I need to convert to EntityList.

 

public EntityList<GSC.Entities.PayrollTrxLines> GetPayrollTrxLinesByEmployee(string code, EntityList<GSC.Entities.PayrollTrxLines> AlltrxLines)

        {

 

            Predicate<PayrollTrxLines> filter = delegate(GSC.Entities.PayrollTrxLines attribute)

            {

                if (attribute.EmployeeCode != null

                    && attribute.EmployeeCode.Equals(code))

                    return true;

 

                return false;

            };

 

            System.Collections.Generic.List<GSC.Entities.PayrollTrxLines> filterObj = AlltrxLines.FindAll(filter);

 

            if (filterObj.Count > 0)

                return filterObj as EntityList<GSC.Entities.PayrollTrxLines>;

 

            return null;

        }

 




Replies:
Posted By: IdeaBlade
Date Posted: 12-Jul-2007 at 3:44pm

You must use List, not EntityList.

Try using a List<PayrollTrxLines> instead of an EntityList<PayrollTrxLines> as in this example from Reference Help

 

     PersistenceManager pm = PersistenceManager.DefaultManager;

 

     // Retrieve all customers.

     EntityList<Customer> allCustomers = pm.GetEntities<Customer>();

     System.Diagnostics.Debug.WriteLine(allCustomers.Count.ToString());

 

     // Define find criteria - this looks for companies beginning with letter 'A'.

     Predicate<Customer> filter = delegate(Customer pCustomer) {

       return pCustomer.CompanyName.StartsWith("A");

     };

 

     // Find a subset of customers.

     List<Customer> AListCustomers = allCustomers.FindAll(filter);

     Console.WriteLine(AListCustomers.Count.ToString());

 

 




Print Page | Close Window