Can you use Linq to filter an existing EntityCollection?

Posts   
 
    
nato24 avatar
nato24
User
Posts: 14
Joined: 10-Apr-2007
# Posted on: 12-Sep-2008 23:40:23   

Lets say I have an EntityCollection of Employees. I want to bind that collection to two different grids. Is there a way for me to filter the EmployeeEntityCollection on a field/property?

I'm currently looping through the collection to create 2 different EntityCollections which seems like the wrong approach.

Any suggestions?

Thanks, Nathan

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Sep-2008 03:31:12   

Hi Nathan,

You could try this:
List<EmployeeEntity> filteredInMemoryEmployees = 
    (from e in fetchedEmployees
        where e.Country == "USA"
        select e).ToList();

You also could use EntityViews.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39863
Joined: 17-Aug-2003
# Posted on: 13-Sep-2008 10:46:13   

I think using entityviews is better, because you can filter the views differently, on the same collection and manipulate the same collection through both views. this gives less overhead when working with the entities afterwards as you have just 1 collection to save.

See the DelegatePredicate in the documentation how to use it with a lambda to filter an entityview simple_smile

Frans Bouma | Lead developer LLBLGen Pro
nato24 avatar
nato24
User
Posts: 14
Joined: 10-Apr-2007
# Posted on: 14-Sep-2008 05:06:27   

Perfect, thanks. I didn't know about the EntityView gem.

I'm thinking I really need to read the documentation front to back.

Nathan

nato24 avatar
nato24
User
Posts: 14
Joined: 10-Apr-2007
# Posted on: 18-Sep-2008 19:42:12   

Hmm... I must be missing something as I have no EntityView class in my generated code. I have the following references in the VS project.

  • SD.LLBLGen.Pro.DQE.SqlServer.NET20
  • SD.LLBLGen.Pro.ORMSupportClasses.NET20 I'm using 2.6, but only have a few entities mapped on tables. Do you not get the EntityView class unless add something else to your project?

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39863
Joined: 17-Aug-2003
# Posted on: 18-Sep-2008 20:35:50   

EntityView<T> (SelfServicing) and EntityView2<T> (Adapter) are in the ORMSupportClasses, as generic classes. You should see them simple_smile

Frans Bouma | Lead developer LLBLGen Pro