Copy Field to StringList

Posts   
 
    
softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 17-Sep-2007 15:03:35   

Hi experts,

is there a way to copy the content of a single field to a stringlist?

Example: Assume we have a collection of customers. The collection entities consist of three fields: CusID, CusName, CusLocation.

What I need is to copy all CusID's to a list<string>. One trivial approach would be to iterate through all customer entities and do something like this:


list<string> customerIDs = new list<string>;
foreach (customerEntity customer in customerCollection)
{
    customerIDs.Add(customer.CusID.ToString());
}

I'm just curious if there is a more elegant and performant way to solve this task. Using LLBL 2.0.0.0.

Thanks! Ingmar

softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 17-Sep-2007 15:24:28   

Sorry, I forgot to mention that it would be ok too, if I could copy the CusID's to an array. So, either list<string> or long[] as target would be fine for me.

DvK
User
Posts: 323
Joined: 22-Mar-2006
# Posted on: 17-Sep-2007 17:35:55   

Use Projection functionality ! Generated code - Using the EntityView2 class, Adapter -> Projecting data inside an EntityView2 on another data-structure

softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 17-Sep-2007 18:51:37   

Hello DvK,

thank you very much for your suggestion. Well, using SelfService, after all I got it working so far:

CustomerCollection allCustomers = new CustomerCollection();
allCustomers.GetMulti(null);
EntityView<CustomerEntity> allCustomersView = allCustomers.DefaultView;
List<myCustomer> myCusIDs = new List<Customer>(); DataProjectorToCustomClass<myCustomer> customClassProjector = new DataProjectorToCustomClass<myCustomer>(myCusIDs);
List<IEntityPropertyProjector> propertyProjectors = new List<IEntityPropertyProjector>();
propertyProjectors.Add(new EntityPropertyProjector(CustomerFields.CusID, "cusID"));
allCustomersView.CreateProjection(propertyProjectors, customClassProjector);

with

public class myCustomer
{
    private long _cusID;

    public myCustomer()
    {
        _cusID = 0;
    }

    public long cusID
    {
        get { return _cusID; }
        set { _cusID = value; }
    }
}

So, "myCusIDs" contains all the cusID's I was looking for.

Though "myCusIDs" is neither of list<string> nor long[]. And I need these datatypes to go into the AddWithAnd-clause of another PredicateExpression. I guess I'm just one little step away...but I don't see the solution.

Thanks again! Ingmar

DvK
User
Posts: 323
Joined: 22-Mar-2006
# Posted on: 17-Sep-2007 22:38:12   

OK, yeah...that's true....I guess it's not (yet) possible to directly fill a List(Of Int) based on an Int column within an entitycollection. Perhaps Otis or Walla has an answer to this ?!

softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 18-Sep-2007 04:23:37   

Thanks DvK! Yes, that would be great if one of them knows a solution...

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Sep-2007 11:22:27   

list<string> customerIDs = new list<string>; foreach (customerEntity customer in customerCollection) { customerIDs.Add(customer.CusID.ToString()); }

IMHO, your first approach is the best one. I can't think of more elegant way.

softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 18-Sep-2007 11:25:27   

All right. Good to know! Thank you, Walaa.