Ticket Q481801
Visible to All Users

Session.DataLayer is null (nothing in Visual Basic) in Middle-Tier scenario - Use ObjectSpace or Session.ObjectLayer instead

created 12 years ago

Hi,
I have an XAF application with a ViewController with these lines of code:
Session session = (this.gridListView.ObjectSpace as XPObjectSpace).Session;
UnitOfWork uow = new UnitOfWork(session.DataLayer);

Everythings works fine but I have to use a middle tier application server. Using that, the application comes up correctly, but (when the view controller above) executes the second line of the code, the DataLyer is null.
Can you please help?
many thanks,
Marco

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hello Marco,
I recommend you use the View.ObjectSpace property to query and manipulate your data, if possible.
This is because it will always work correctly regardless of whether you are using a middle-tier server or not.
If, for some reason, you cannot follow this recommended approach, use the Session.ObjectLayer property instead of the Session.DataLayer one.
I hope this helps.
UPDATE:
I have just blogged about this scenario.

    Show previous comments (1)
    Dennis Garavsky (DevExpress) 12 years ago

      You are always welcome, Marco.
      P.S.
      I have just blogged about your scenario: dennisgaravsky.blogspot.com/2013/03/beware-of-sessiondatalayer-in-middle.html

      RE RE
      Reinhold Erlacher 11 years ago

        Hello Dennis,
        I have an additional question to this subject. Do I Need to move generators to Server?
        If so, could you post some lines, how to handle this in middle Tier situations?
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            Number = DistributedIdGeneratorHelper.Generate(this.Session.DataLayer, this.GetType().FullName, string.Empty);
        }
        If needed, please move to a new ticket. thanks
        Regards
        Reinhold

        Dennis Garavsky (DevExpress) 11 years ago

          @Reinhold: As mentioned in the How to generate a sequential and user-friendly identifier field within a business class example this generator does not yet support the middle-tier scenario.

          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.