Ticket Q559655
Visible to All Users

PersistentAlias parameters

created 11 years ago

Hi,

I am going to need to be able to have something like the concept of 'parameters' in PersistentAlias expressions. the scenario I have is this:

This is a legacy database - many 'companies' share the same tables, but there is an identifier column 'CompanyID' - string type on the table that says which 'company' the data belongs to. When the session is created, we know which 'company' we are working on, and so could for instance provide this data as a Dictionary to the session/unit of work in question. We need to be able to only return the result for the correct company.

For instance:

[PersistentAlias("[<DepartmentsXpo>][CompanyID = ?CompanyDSDepartmentsXpo && DepartmentID = ^.DepartmentID].Single()")]

public DepartmentsXpo DepartmentIDXpo

{

get { return GetValue<DepartmentsXpo>(null,"DepartmentIDXpo"); }

}

Where ?CompanyDSDepartmentsXpo is a value in the Dictionary that we know for the session. Each table in the session would have a different parameter that needed to be checked against to get the correct record for that company, as some companies share the tables!

Now, I can't see how this can be done at present so I wondered if this could be performed as an enhancement (seems simple enough, have a 'parameters' dictionary object for session, we populate that when creating the session, and then the PersistentAlias mechanism looks for a key in the dictionary matching the parameter and replaces the parameter with the value).

Alternatively I was wondering if it could be performed with current functionality through custom functions, and if so if you could point me in the right direction with an example for what I am looking to achieve?

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hi Andrew.
If your application works with one company at a time, you can replace this parameter with a custom function that returns a value stored in a static variable.

C#
public class CurrentCompanyIdOperator : ICustomFunctionOperator { public const string OperatorName = "CurrentCompanyId"; public static object CurrentCompanyId { get; set; } private static readonly CurrentCompanyIdOperator instance = new CurrentCompanyIdOperator(); public static void Register() { CriteriaOperator.RegisterCustomFunction(instance); } public object Evaluate(params object[] operands) { return CurrentCompanyId; } public string Name { get { return OperatorName; } } public Type ResultType(params Type[] operands) { return typeof(object); } }

Another solution is to remove the PersistentAlias attribute from this property and perform the calculation in the property getter:

C#
public DepartmentsXpo DepartmentIDXpo { get { return Session.FindObject<DepartmentsXpo>(CriteriaOperator.Parse("CompanyID = ? && DepartmentID = ?", GetCompanyDSDepartmentsXpo(), this.DepartmentID)); } }

If you need to associate some data with a session instance, you can use methods of the DevExpress.Xpo.Helpers.IWideDataStorage interface that the Session class implements. However, this interface is not documented and designed for internal use.

    Show previous comments (19)
    DevExpress Support Team 9 years ago

      Thanks for the clarification. This functionality isn't planned for any specific release date. At present, I suggest that you use separate data layers with customized metadata dictionaries, where parameter values are embedded into PersistentAlias criteria.

      AT AT
      Andrew Thornton 9 years ago

        Therein lies the problem.

        1. with up to 2000 tables in each datalayer it takes long enough to make 1 (changing the table names), so 10+ takes an embarrassingly long amount of time.  It's already been commented on.
          This is what I'm trying to get away from by reducing the tables down to a single one for all companies which always has a fixed name.
        2. All our persistentaliases (probably 10000+) are hard coded again the classes.  So what are we supposed to do - read the existing ones, automatically try to tag the extra column and filter onto it?  Can't see that taking long programmatically or being flawaed at all!
        3. It doesn't fix my other problem which is some queries we do are based on filter criteria the customer is using for that query/report.  Another query/report would need to use different criteria.  Add new persistentaliases on the fly when the datalayer has been generated?  Can't see it.
        4. Our table names can actually change on the fly, but we can't currently handle that in the new .Net system (can in the cobol system…)
          Really need a session dictionary passing down to the filter for it's use.
        DevExpress Support Team 9 years ago

          Thank you for describing your difficulties. Unfortunately, we don't have another solution to offer at the moment. If your model needs to be so flexible, possibly XPO is not the right choice for this application.

          Other Answers

          created 8 years ago (modified 7 years ago)

          We have changed a few lines in the devexpress code to add a new 'Customfilterobject' to the session class, and pass this down to the custom function as an operand.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.