Sample Usage

The following is a brief example of how one might use the Attributes of XpoImport to load data from a SQL Table into XPO Obejcts.  The process of importing from a SQL table (tables) is very simple:

1. Add the TableImport attribute to each class you wish to import data for
2. Add FieldImport attributes to each field
3. Run XpoImport and specify the Assembly containing your business objects.

    [TableImportIndex(1)]    // Import this Class (Index 1 specified the import order)
    [TableImport("tblAreas", "AREAID")]   // Import from the tblAreas table 
    public class Area : XPObject
    {
        private string _Name;
        [Size(20)]
        [Indexed(Unique = true)]
        [FieldImport("SEARCHTEXT")]  // Import the value of Name from the SEARCHTEXT field in tblAreas
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                SetPropertyValue("Name", ref _Name, value);
            }
        }

        private string _Description;
        [Size(50)]
        [FieldImport("DESCRIPTION")]  // Import Description from 'DESCRIPTION' field in tblAreas
        public string Description
        {
            get
            {
                return _Description;
            }
            set
            {
                SetPropertyValue("Description", ref _Description, value);
            }
        }

Another example:

    public class Resort : XPObject
    {
        Area _Area;
        [FieldImport("AREAID", FieldImportAttribute.FieldConversionType.Lookup)]  // Link to a related XPO Object using the association 
        [Association("Area-Resorts")]
        public Area Area
        {
            get { return _Area; }
            set { SetPropertyValue<Area>("Area", ref _Area, value); }
        }

Last edited Nov 9, 2010 at 8:56 AM by ShawInnes, version 1

Comments

No comments yet.