From the above query we can get a list of customers that are 25 years old . As you can see the code is very simple.

The problemWhen working with modularized applications you may be in context that you have access to the Customer type only at runtime or you may want to apply that query to different object types that all have an Age property. How that can be done?

1st attempt

Lets register the customer to our module and use reflection to create the XPQuery.

//although we can construct the XPQuery object we have to stop here cause there is no way to use it since we not have the type at design time

}

2nd Attempt

Refactor our customer using an ISupportAge interface that will live in our module and use that interface with the DoQuery method

publicinterfaceISupportAge {

intAge { get; set; }

}

publicclassCustomer : BaseObject, ISupportAge {

publicCustomer(Session session) : base(session) {

}

privateint_age;

publicintAge {

get {

return_age;

}

set {

SetPropertyValue("Age", ref_age, value);

}

}

}

Now the DoQuery will have no arguments

ModuleXXX moduleXxx = newModuleXXX();

moduleXxx.DoQuery();

and will look like

publicIQueryable<ISupportAge> DoQuery() {

var xpQuery = newXPQuery<ISupportAge>(Session.DefaultSession);

return xpQuery.Where(customer => customer.Age == 25);

}

as you see in the code above in order to be able to use lamda expressions i have passed the ISupportAge interface in my XPQuery method. Too bad that XPQuery supports as generic parameters only persistent types and not interfaces

3rd Attempt

The previous attempt was pretty closed to what we wanted. Brainstorming and researching a little more we can find that lambda expressions are fully decomposable. That means that they consist of parts like body,parameters,sub expressions that can be decomposed and recomposed again. After decomposing the tree using Xpand.Utils.Linq.ExpressionConverter the DoQuery method now will look similar to

Monday, November 1, 2010

In the post I am going to speak about our latest addition which is support for runtime orphaned collections.

Using Model Editor

As you see in the image bellow you only have to create a new IModelRuntimeOrphanedColection

set CollectionType attribute (1)

and filter the collection by using the criteria (2).

Although the Model Editor approach with a combination of the ModelDifference module can provide great flexibility such as defining Runtime Collections for a set of Roles or Users has a drawback. It does not add those collections in any of your views. You have to do that manually.

Welcome to my Blog

My name is Apostolis Bekiaris and I am working for DevExpress as a technical evangelist for the frameworks team, .Net is my passion and at this blog you will find a lot of my work using DevExpress Xaf framework and many others. If you want to contact me you can use the link bellow