Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Architecture> Understanding filtering of EntityViews
 

Pages: 1
Architecture
Understanding filtering of EntityViews
Page:1/1 

  Print all messages in this thread  
Poster Message
Scooter
User



Location:
USA
Joined on:
28-Jul-2006 21:40:24
Posted:
2 posts
# Posted on: 28-Jul-2006 21:48:44.  
I am really trying to get my head around the filtering of entityviews. We just migrated to LLbL 2.0 and prior to that our code looked like this:

Dim CurrentRoleEntity As EntityClasses.RolesEntity

grdMain.DataSource = CurrentRoleEntity.MenuRoles

Well, I now have a need to apply a filter to this, and in all the reading both in LLBL forums and LLBL documentation, I gather that EntityViews are the way to go. However, I am struggling with how to apply that to the code above.

Any insight is greatly appreciated.

Thanks...

Scott
  Top
bclubb
User



Location:
Norman, Oklahoma
Joined on:
12-Feb-2004 22:18:04
Posted:
934 posts
# Posted on: 29-Jul-2006 04:04:54.  
Give something like this a try. The view operates on the collection you already have in memory.

Code:
Dim CurrentRoleEntity As EntityClasses.RolesEntity

Dim menuRolesView As New EntityView(Of MenuRolesEntity)(CurrentRoleEntity.MenuRoles)

Dim filter As IPredicate = (MenuRoleFields.Role = "Admin")
menuRolesView.Filter = filter
gridMain.DataSource = menuRolesView


Let us know if you have any issues with this example.


  Top
Scooter
User



Location:
USA
Joined on:
28-Jul-2006 21:40:24
Posted:
2 posts
# Posted on: 31-Jul-2006 17:26:35.  
Thanks bclubb. Greatly appreciated. That worked great and certainly cleared things up a bit.

One last question. I have been researching this morning trying to find a way to join that in-memory entity to another entity (via a relation) and then apply a filter to the second entity using the code you sent (or something similar).

Did I explain that ok?

Thnaks again...

Scott
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37375 posts
# Posted on: 31-Jul-2006 18:43:43.  
You can't filter an entityview on a related entity. If you want to do that, you should map a field mapper onto a related field (e.g. Order.CompanyName is mapped onto Order.Customer.CompanyName) and filter on that, using EntityProperty(). See for usage of Entityproperty the entityview documentation.

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
alexdresko
User



Location:
Greenville, SC
Joined on:
08-Jun-2004 17:30:02
Posted:
336 posts
# Posted on: 10-Oct-2006 20:39:20.  
Otis wrote:
You can't filter an entityview on a related entity. If you want to do that, you should map a field mapper onto a related field (e.g. Order.CompanyName is mapped onto Order.Customer.CompanyName) and filter on that, using EntityProperty(). See for usage of Entityproperty the entityview documentation.

Is this planned by any chance? If EntityViews supported the same filtering capabilities as standard collections, this would go a long way towards supporting unit testing..

For example, I want to write unit tests that verify my filters are working correctly but without actually having to go to the database. EntityViews would be perfect for that!
I'm not a player, I just code a lot.   Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37375 posts
# Posted on: 11-Oct-2006 08:37:04.  
alexdresko wrote:
Otis wrote:
You can't filter an entityview on a related entity. If you want to do that, you should map a field mapper onto a related field (e.g. Order.CompanyName is mapped onto Order.Customer.CompanyName) and filter on that, using EntityProperty(). See for usage of Entityproperty the entityview documentation.

Is this planned by any chance? If EntityViews supported the same filtering capabilities as standard collections, this would go a long way towards supporting unit testing..

It is planned, though I've no idea at this time how it will pan out, as I can see it will be rather tough to implement in memory, but nevertheless, I also want the feature so it's on the list Regular Smiley



Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
alexdresko
User



Location:
Greenville, SC
Joined on:
08-Jun-2004 17:30:02
Posted:
336 posts
# Posted on: 11-Oct-2006 15:08:25.  
Otis wrote:
alexdresko wrote:
Otis wrote:
You can't filter an entityview on a related entity. If you want to do that, you should map a field mapper onto a related field (e.g. Order.CompanyName is mapped onto Order.Customer.CompanyName) and filter on that, using EntityProperty(). See for usage of Entityproperty the entityview documentation.

Is this planned by any chance? If EntityViews supported the same filtering capabilities as standard collections, this would go a long way towards supporting unit testing..

It is planned, though I've no idea at this time how it will pan out, as I can see it will be rather tough to implement in memory, but nevertheless, I also want the feature so it's on the list Regular Smiley


I was thinking about this some last night and I don't think it can produce guaranteed results.. The current filtering mechanism is dependent on whatever database the generated code is bound to. So if I create a filter before I fetch a collection, I'm really passing a query to SQL and telling it to return the results I want. SQL handles that logic. Whereas your in-memory filtering will be based on whatever algorythm you decide is best. Therefore, the results might not always be the same.

How likely do you think that would be though?
I'm not a player, I just code a lot.   Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37375 posts
# Posted on: 12-Oct-2006 11:43:42.  
I don't exactly understand what you mean by 'it can give different results'.

At the moment you can filter a view based on the data in the entities in the collection the view is a view of.

This should be extended to a filter mechanism which let you filter a view based on data related to that data in the entities in the collection the view is a view of, and I think that's doable, and should give the results you expect, as it works with in-memory data ONLY. So if you fetch a hierarchy, you should be able to get a view of a collection in that hierarchy based on a filter which filters on related data. For example: you fetch customers and orders. It should be possible to filter the customer view based on a filter on orders.

It's perhaps a hard thing to program, I'm not sure, I haven't looked into the gory details yet. The main thing is that it should be unwinded from leaf to root, using simple set logic: first filter the orders, then see if that set offers any results, yes then mark that predicate as true in the whole equation of predicates. If the whole set of predicates resolves to true for that customer, the customer is accepted.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Jazz
User



Location:
Berlin, Germany
Joined on:
12-Aug-2005 17:53:10
Posted:
63 posts
# Posted on: 09-Sep-2008 20:54:47.  
Hi there,

I hate to bring that topic up again but is it still not possible to filter on a related entity? Fear I cannot use the EntityProperty as I got the following structure.

Order 1:n Prices and I want to filter on prices. I dont have the option to filter it from the database as I want to use both filtered and unfiltered collection on a disconnected client.

Regards,
André
  Top
arschr
User



Location:
Atlanta, Georgia; USA
Joined on:
14-Dec-2003 16:57:29
Posted:
876 posts
# Posted on: 09-Sep-2008 22:08:55.  
I believe entityviews can be filtered on values of fields in related entities, at least in 2.5ish versions.

- Al  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8048 posts
# Posted on: 10-Sep-2008 08:39:04.  
If you are using LLBLGen v2.x, you should do that this way: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7100&StartAtMessage=0&#39212

If you are using v2.6 and .NEt3.5+, you could use LINQ to Objects:
Code:
var results = (from o in fetchedOrders
                         where o.Prices.Where(p => p. Discontinued == false).Count() > 0
                         select o);

List<OrderEntity> filteredInMemoryOrders = q.ToList();


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Jazz
User



Location:
Berlin, Germany
Joined on:
12-Aug-2005 17:53:10
Posted:
63 posts
# Posted on: 10-Sep-2008 16:48:49.  
Thanks for your reply. Today I migrated from V2.5 to V2.6, but I'm not planning to use .NET 3.5 anytime soon. So with V2.6 and .Net 2.0 my problem won't be solved using the EntityView?

Regards,
André


  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8048 posts
# Posted on: 12-Sep-2008 20:24:57.  
Hi André. In that case, this is the way I would do that:

In a partial class, write a property that return the number on prices accordingly to some in-memory filter.
Code:
namespace Northwind.Model.EntityClasses
{
    public partial class OrderEntity
    {
        public int DiscountedPricesCount
        {
            get
            {
                return this.Prices.FindMatches(PriceFields.Discountinued == false).Count;                
            }
        }
    }
}


Then you could use that property to create your EntityView:
Code:
EntityView2<OrderEntity> filteredInMemoryOrders = new EntityView2<OrderEntity>(fetchedOrders, new EntityProperty("DiscountedPricesCount") > 0);
David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Jazz
User



Location:
Berlin, Germany
Joined on:
12-Aug-2005 17:53:10
Posted:
63 posts
# Posted on: 15-Sep-2008 17:52:48.  
Thank you David, that did the job!

Regards,
André


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.