CreateView using related field in predicate expression

Posts   
 
    
SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 28-Jun-2013 15:30:58   

Using LLBLGen 4.0 self servicing.

Hi, I want to create a view from a collection using a related entity field in the predicate expression.

IEntityView view = ((IEntityCollection)DataSource).CreateView(predicateExpression, sortExpression);

The view contains zero items and it also doesn't raise an exception; what am I doing wrong ?

Thanks for the help in advance.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Jun-2013 08:10:14   

You can't filter on a related entity that way. You could add a custom property that map the related field (field mapped onto related entity) and filter on that. Something like:

public partial class OrderEntity
{
     public string CustomerName
    {
        get { return this.Customer.CompanyName; }
    }
}

....

predicateExpression.Add(new EntityProperty("CustomerName") == "Some value");
IEntityView view = ((IEntityCollection)DataSource).CreateView(predicateExpression, sortExpression);

You also could use Linq2Objects. Ref: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7100&StartAtMessage=0&#79516

David Elizondo | LLBLGen Support Team
SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 01-Jul-2013 16:48:59   

Clear

Thanks a lot David