Use MetaColumn in PredicateExpression

Posts   
 
    
lubo278
User
Posts: 32
Joined: 10-Apr-2007
# Posted on: 24-Feb-2009 11:33:04   

Hi,

not to bother You with details - I have MetaColumn and want to use it in PredicateExpression simple_smile . Ok sounds bad, but this way I ended (it is for generic filter control, which takes MetaColumn as parameter and generates IPredicateExpression as output).

So I would like to create something like this

public IPredicateExpression GetExpression(MetaColumn column)
  {
// this works great
    return new PredicateExpression(BookingRoomFields.Created > DateTime.Now.AddMonths(-6));
  }

ok, so is it possible to make something like this?

public IPredicateExpression GetExpression(MetaColumn column)
  {
// this does not work of course
  return new PredicateExpression(column > DateTime.Now.AddMonths(-6));
  }

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 24-Feb-2009 21:21:40   

Does your MetaColumn contain some information, or inherit from something, which will allow you to determing the field on which the filter is to be applied ?

If not, I can't see how you could do this - if it does it should be possible to get this information out...

Matt

lubo278
User
Posts: 32
Joined: 10-Apr-2007
# Posted on: 25-Feb-2009 13:34:37   

MTrinder wrote:

Does your MetaColumn contain some information, or inherit from something, which will allow you to determing the field on which the filter is to be applied ?

If not, I can't see how you could do this - if it does it should be possible to get this information out...

Matt

MetaColumn is** System.Web.DynamicData.MetaColumn** (the filter I want to create is Dynamic Data filter). MetaColumn class contains string name of the "column" in database and link to MetaTable object (which contains name of LLBL entity). In fact it had to be in some point generated from LLBL objects (only there is not obvious mapping between them).

However it does not link directly to LLBL objects. But LLBLGenProDynamicDataSource can use filtering on these MetaColumns (I can't see how it does it). So I hoped there is some magic mapping class which I could use.

My second though was to give up PredicateExpression in filters and use only Parameter (SearchParameter, QueryParameter, etc.) objects. These could be directly mapped to WhereParameters of LLBL datasource. But it is not so flexible as PredicateExpression (i.e. multicolumn filters).

PS: I know it is rather more Dynamic Data (+LLBL) problem than LLBL. But I am very close to combine these two solutions (with DB stored RBAC permissions, field and filters settings).

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 25-Feb-2009 18:14:01   

lubo278 wrote:

MTrinder wrote:

Does your MetaColumn contain some information, or inherit from something, which will allow you to determing the field on which the filter is to be applied ?

If not, I can't see how you could do this - if it does it should be possible to get this information out...

Matt

MetaColumn is** System.Web.DynamicData.MetaColumn** (the filter I want to create is Dynamic Data filter). MetaColumn class contains string name of the "column" in database and link to MetaTable object (which contains name of LLBL entity). In fact it had to be in some point generated from LLBL objects (only there is not obvious mapping between them).

However it does not link directly to LLBL objects. But LLBLGenProDynamicDataSource can use filtering on these MetaColumns (I can't see how it does it). So I hoped there is some magic mapping class which I could use.

The filtering all happens through normal SelectParameter elements like with normal datasource controls.

The MetaColumn objects are produced by Dynamic Data from the meta information provided to it by the Dynamic data model provider located in the DynamicDataSupportClasses.

the MetaColumn's Table property provides the MetaTable object, which contains the EntityType value, which is the type of the entity, the name of the entity, and for example a reference to the Model. Using the EntityType, you can obtain an entity instance, or use the type with the generated EntityFactoryFactory (stuck_out_tongue_winking_eye ) type to obtain a factory for the entity at hand.

With the factory (or the entity instance, i'd use the factory), you can create a new entity instance. With that instance you can obtain the field with name MetaColumn.Name simple_smile So what you could do is create a utility method which receives a MetaColumn, grabs its Table property, then grab that one's EntityType type, pass that to the EntityFactoryFactory (generated class in FactoryClasses), to create a new Entity instance and obtain the field by using entity.Fields[MetaColumn.Name]

You can THEN pass that field in the predicate: return new PredicateExpression(obtainedentityField > DateTime.Now.AddMonths(-6));

Frans Bouma | Lead developer LLBLGen Pro
lubo278
User
Posts: 32
Joined: 10-Apr-2007
# Posted on: 25-Feb-2009 18:55:08   

LOL, I was close though...

The solution (at least my interpretation)

IEntityFactory entityFactory = EntityFactoryFactory.GetFactory(Column.Table.EntityType);
EntityField field = (EntityField)entityFactory.CreateFields()[Column.Name];

return new PredicateExpression(field < DateTime.Now);

And it works like a charm, thanx.