In my DAL I have a data access object that retrievs database records to an EntityObject List:
private List<EntityObject> entities;
var pList = context.Products.Where(...);
entities = new List<EntityObject>(pList);
To work with this List in my BI layer I need to enumarate through this List<EntityObject> as a list of Product objects. I can easily convert back like this:
var pList = Data.Entities.Select(p => p as Product);
but doesn’t this create a copy of the List<EntityObject> doubling my memory footprint for this collection which would be a concern with large collections?
If so, is there a way to enumarete through this List<EntityObject> as List<Product> instead of converting back to Product and than enumerating through that copy?
No, this would just make a copy of the references to the entities, so that should be of no concern.
Also a safer way to do your cast would be:
Or you can just directly enumerate through the products: