in
Forums
Blogs
Files
Devexpress.Com
ClientCenter
Support Center
DevExpress Channel

How to set a default value to a Bo object's property

Last post 8/28/2008 10:34 PM by nie zuan. 6 replies.
Page 1 of 1 (7 items)
Sort Posts:
Previous Next
  • 8/26/2008 9:56 AM

    How to set a default value to a Bo object's property

    hi,I want to know How to set a default value to a Bo object's property,the type of property is a Bo class.

    my Bo Objects as follow:

    ....

      User createdBy;

       public User CreatedBy

    {

           Get{return createdBy;}

           Set{SetProperytValue("CreatedBy",ref createdBy,value);}

    }

    ...

     

    Comments:User is a class within XAF.

  • 8/26/2008 11:37 AM In reply to

    Re: How to set a default value to a Bo object's property

    Try adding this to your class:

    protected override void OnSaving()
            {
                // Set your default values here
                base.OnSaving();
            }

     

    This is just one way to set default values, there are other ways depending on your needs (validation etc).

     

    Mohsen

  • 8/26/2008 3:25 PM In reply to

    Re: How to set a default value to a Bo object's property

    Hi Nie,

    You can use AfterConstruction() to initialize some fields to a default value.
    AfterConstruction() gets only called for a new object, it is not called for an object recreated from the DB.

    public override void AfterConstruction() {
    base.AfterConstruction();
    CreatedBy = ...;
    }

    Regards,
    Marc Greiner [DX-Squad]
  • 8/28/2008 2:10 AM In reply to

    Re: How to set a default value to a Bo object's property

     Thx,I want to ask another question that how to load data from database in a Bo class via code ?

     

     

  • 8/28/2008 6:16 AM In reply to

    Re: How to set a default value to a Bo object's property

    My retrieve data code as bellow:

     

                     XPCollection xpCollection = new XPCollection(typeof(Contact));         
                    CriteriaOperator criteria = CriteriaOperator.Parse("FirstName<>'nie'");
                    xpCollection.Criteria = criteria;
                    int ctr = xpCollection.Count;

     

     the var ctr  still get 0,in fact ,the Contact in DB have two records.

     

  • 8/28/2008 1:38 PM In reply to

    Re: How to set a default value to a Bo object's property

    You need to use the right Session object in the constructor of the collection. By default, the Session,DefaultSession is used and it is targeted to the Access database located near your executable file.

    Thanks,
    Dennis

    Developer Express Support
  • 8/28/2008 10:34 PM In reply to

    Re: How to set a default value to a Bo object's property

      Dennis :Thank you ,I solved this problem

Page 1 of 1 (7 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED