Create predicate for generic TypedView

Posts   
 
    
Rubio
User
Posts: 3
Joined: 09-Apr-2008
# Posted on: 09-Apr-2008 21:12:33   

Hi! First of all, congratulations for your application it's amazing, and second, excuse me for my english, it's not good. I'm using LLBLGen Pro version 1.2004.2 final, with SQL Server database (SelfServicing) , and I have a little problem: I'm trying to create a generic function that creates a filter (predicate) for any TypedView, depending on a table that contains a list for the identity column of de TypedView. I did it using a Collection, here is the code:

    
private PredicateExpression ObtenirPredicateForCollection(SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection _collection, DataTable tblIdents)
{
    PredicateExpression p = new PredicateExpression();

    //Get the array of identifiers of the column o the datatable
    List<object> codis = new List<object>();
    foreach (DataRow rw in tblIdents.Rows)
    {
        codis.Add(rw[0]);
    }

    //Create Range predicate by idents in the list and the column's name of the datatabe
    IEntity ent = _collection.EntityFactoryToUse.Create();
    FieldCompareRangePredicate fp = new FieldCompareRangePredicate(ent.Fields[tblIdents.Columns[0].ColumnName], codis.ToArray());

    p.Add(fp);

    return p;
}

Now I would like to do the same but using ITypedView interface, but I can't find any method or property for generate de EntityFields needed for create the predicate. In this project, I have no reference to generated code project of specific database, I only have a reference to SD.LLBLGen.Pro.ORMSupportClasses. Whereas in IEntityCollection interface there is a property EntityFactoryToUse that allows acces to collection fields for create the Predicate Expression, in TypedViews I haven't found one.

Thanks for all Xavi simple_smile

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Apr-2008 11:51:14   

private PredicateExpression ObtenirPredicateForCollection(**IEntityCollection _collection**, DataTable tblIdents)

In the above method, if you are already passing the collection with the specific entityFactory, then you could have passed the entity itself instead of passing the collection.

Like so:

private PredicateExpression ObtenirPredicateForCollection(IEntity _entity, DataTable tblIdents)

Similarly for ITypedView you can do the following:

private PredicateExpression ObtenirPredicateForCollection(ITypedView _view, DataTable tblIdents)
Rubio
User
Posts: 3
Joined: 09-Apr-2008
# Posted on: 10-Apr-2008 12:13:39   

Sorry, i think i have no explained my problem well enough.flushed flushed The code I exposed, works correctly for a collection interface, but now I'm trying to do the same with the TypedView interface, but I can't find a method or propierty like:

_collection.EntityFactoryToUse.Create()

which allow me to acces to typedview fields for create the predicate:

 FieldCompareRangePredicate fp = new FieldCompareRangePredicate(ent.Fields[tblIdents.Columns[0].ColumnName], codis.ToArray());

If I pass a ITypedView, an exception is launched because ITypedView doesn't implement EntityFactoryToUse

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Apr-2008 12:34:33   

I understand that the EntityCollection method is working. I was explaning that it could have worked in the following way:

private PredicateExpression ObtenirPredicateForCollection(IEntity _entity, DataTable tblIdents)
{
    PredicateExpression p = new PredicateExpression();

    //Get the array of identifiers of the column o the datatable
    List<object> codis = new List<object>();
    foreach (DataRow rw in tblIdents.Rows)
    {
        codis.Add(rw[0]);
    }

    //Create Range predicate by idents in the list and the column's name of the datatabe

    FieldCompareRangePredicate fp = new FieldCompareRangePredicate(_entity.Fields[tblIdents.Columns[0].ColumnName], codis.ToArray());

    p.Add(fp);

    return p;
}

The question is why do you pass an entityCollection?

Having said that then the following should work:

private PredicateExpression ObtenirPredicateForCollection(ITypedView _view, DataTable tblIdents)
{
    PredicateExpression p = new PredicateExpression();

    //Get the array of identifiers of the column o the datatable
    List<object> codis = new List<object>();
    foreach (DataRow rw in tblIdents.Rows)
    {
        codis.Add(rw[0]);
    }

    //Create Range predicate by idents in the list and the column's name of the datatabe

    FieldCompareRangePredicate fp = new FieldCompareRangePredicate(_view.GetFields()[tblIdents.Columns[0].ColumnName], codis.ToArray());

    p.Add(fp);

    return p;
}
Rubio
User
Posts: 3
Joined: 09-Apr-2008
# Posted on: 10-Apr-2008 13:08:50   

OK! I think the problem i the version of LLBLGen I have (1.0.2004.2 final), because GetFields() method is not present in my version of ITypedView interface. disappointed

Do yo know if there is a way for get the fields of typedview in my LLBLGen version? Or could I try to create a FieldEntity using DataTable's column information? Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 10-Apr-2008 17:19:41   

That method was introduced in v2.0.

What you could do is one of two things: 1) (as the code is from 2004, so it's tad old, and we're only fixing major bugs in that code on request only), altering the ITypedView interface and add GetFields(). Then in the template, add a GetFields() method which calls EntityFieldsFactory.CreateTypedViewEntityFieldsObject(TypedViewType.<typedviewname>TypedView);

2) leave the ormsupportclasses alone and add a new interface to your own code which is implemented in the typedviews. You alter the template as well as described above, but now in your code you cast to your own interface using 'as', and if that results in a non-null object, you call the GetFields() method.

Frans Bouma | Lead developer LLBLGen Pro