I need to return the property name from custom function operator in server mode to allow sorting and filtering:
C#using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using Creasoft.Core;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.Validation;
namespace Creasoft.DataLocalization
{
[DomainComponent]
[XafDefaultProperty("CalculatedProperty")]
public interface IPropertyContainer
{
[Browsable(false)]
string Property1 { get; set; }
[Browsable(false)]
string Property2 { get; set; }
[Browsable(false)]
string Property3 { get; set; }
[Calculated("GetPropertyName()")]// I can't use either static PersistentAlias or CalculatedPersistentAlias because the property name depends from current logged user settings
string CalculatedProperty { get; }
}
[DomainComponent]
[DefaultClassOptions]
public interface ITestDC
{
[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Always)]
IPropertyContainer Container1 { get; set; }
[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Always)]
IPropertyContainer Container2 { get; set; }
[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Always)]
IPropertyContainer Container3 { get; set; }
}
[DomainLogic(typeof(ITestDC))]
public class TestDCLogic
{
public void AfterConstruction(ITestDC instance, IObjectSpace objectSpace)
{
instance.Container1 = objectSpace.CreateObject<IPropertyContainer>();
instance.Container2 = objectSpace.CreateObject<IPropertyContainer>();
instance.Container3 = objectSpace.CreateObject<IPropertyContainer>();
}
}
public class GetPropertyNameFunctionOperator : ICustomFunctionOperatorFormattable
{
#region ICustomFunctionOperatorFormattable Members
// The function's expression to be evaluated on the server.
string ICustomFunctionOperatorFormattable.Format(Type providerType, params string[] operands)
{
return "Property1"; //this is static result, but in my business scenario the returned value depends from the current logged user settings
}
#endregion
#region ICustomFunctionOperator Members
// Evaluates the function on the client.
object ICustomFunctionOperator.Evaluate(params object[] operands)
{
// TODO
}
string ICustomFunctionOperator.Name
{
get { return "GetPropertyName"; }
}
Type ICustomFunctionOperator.ResultType(params Type[] operands)
{
return typeof(string);
}
#endregion
}
}
The problem is that when I trying to sort/filter in the list view - the alias calculates only from client side.
Hello Stanislaw.
Would you please clarify what you mean by "the alias calculates only from client side"? Please expalin exactly what happens in which scenario. A small sample project demonstrating the issue would be helpful.
Hello, Michael!
I've attached a sample project.
Run it and try to sort by any property - you will see that persistent alias evaluates only from client side, but my business case requires that sorting/filtering by any of properties that have a persistent alias attribute with my custom function is processe on the server-side.