Ticket T641574
Visible to All Users
Duplicate

Security - Access DB from CustomizeTypesInfo with Middle-Tier server

created 7 years ago

This relates to my earlier question that I managed to solve on my own shortly after asking it…
https://www.devexpress.com/Support/Center/Question/Details/T641444/runtime-add-member-to-nonpersistent-class

The non-persistent fields I wish to create are derived from data in the database. When accessing the DB directly, it works as desired, but with the Middle-Tier server, I am unable to access the necessary data. I suspect this is not a 'supported' usage, but any tips on how to obtain access to the database at this point in the application startup would be much appreciated.

Comments (3)
DevExpress Support Team 7 years ago

    Hello Eldon,

    To avoid any misunderstanding, please attach your code demonstrating the approach you are using when the application is connected to the database directly.

      TimingContainer is the nonpersistent object containing one set of related fields

      C#
      public override void CustomizeTypesInfo(ITypesInfo typesInfo) { base.CustomizeTypesInfo(typesInfo); IObjectSpace oSpace = Application.CreateObjectSpace(); ITypeInfo tcInfo = typesInfo.FindTypeInfo(typeof(TimingContainer)); if (tcInfo is TypeInfo tcti) { IList<ProjectEventType> eventTypes = oSpace.GetObjects<ProjectEventType>(CriteriaOperator.Parse("Obsolete = False")); foreach (ProjectEventType evt in eventTypes) { IMemberInfo member = tcti.CreateMember("ProjectEvent" + evt.Oid, typeof(ProjectEvent), "Project.TimingEvents[[EventType.Oid] = " + evt.Oid + " And [Rank] = ^.TimingEvents[[EventType.Oid] = " + evt.Oid + "].Max([Rank])].Max([This])"); XafMemberInfo xMember = member as XafMemberInfo; xMember.DisplayName = evt.Label + " Event"; } } typesInfo.RefreshInfo(typeof(BusinessObjects.Persistent.ProjectCore.TimingContainer)); }
      DevExpress Support Team 7 years ago

        Hello Eldon,

        We need additional time to research this scenario. We will get back to you once we have any results or need additional information. Please bear with us.

        Answers approved by DevExpress Support

        created 7 years ago (modified 7 years ago)

        Thank you for your patience.
        The middle-tier application client does not allow you to access data through the Object Space until a user logs on to the security system.
        In order to get data from the database, instantiate an XPObjectSpaceProvider object and pass the connection string to the constructor. Then, call the XPObjectSpaceProvider.CreateObjectSpace method to create an IObjectSpace object. Use methods of the created Object Space to access data.

        As an alternative solution, you can extend a service contract in the WCF and get the data without logon into the security system. But since it's not a XAF specific task, we do not have any special guides for this. For more information, see the Designing Service Contracts article.
        Also, you can consider getting the necessary data to customize TypeInfo from other sources (for example, load a XML document from the file system).

        See also:
        Middle Tier Security - WCF Service
        How to: Connect to the WCF Application Server from Non-XAF Applications
        Access XAF Application Data in a non-XAF Application

          Comments (2)

            Thank you; I finally got back around to this task to try out the solution.

            I chose to use the Custom WCF client option from "How to: Connect to the WCF Application Server from Non-XAF Applications", and that seems to be working as desired.
            As one of the primary reason for me using the middle-tier server is to hide the connection string, the first suggestion of using XPObjectSpaceProvider did not suit my needs.

            DevExpress Support Team 7 years ago

              I am glad to hear that you have found a solution. Do not hesitate to contact us if you need further assistance.

              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.