using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord.Framework;
using Castle.ActiveRecord.Framework.Config;
using Castle.ActiveRecord;
using System.Reflection;

namespace NestedDataExample
{
    [ActiveRecord]
    public class Osoba : ActiveRecordBase
    {
        [PrimaryKey]
        public int ID { get; set; }
        [Property]
        public string ImieNazwisko { get; set; }
        [Nested(ColumnPrefix="A1")]
        public Adres Adres1 { get; set; }
        [Nested(ColumnPrefix="A2")]
        public Adres Adres2 { get; set; }
    }

    public class Adres
    {
        [Property]
        public string Kod { get; set; }
        [Property]
        public string Miasto { get; set; }
        [Property]
        public string Ulica { get; set; }
    }

    class Program
    {
        static void Main( string[] args )
        {
            IConfigurationSource source = ActiveRecordSectionHandler.Instance;
            ActiveRecordStarter.Initialize( Assembly.GetAssembly( typeof( Program ) ), source );
            ActiveRecordStarter.DropSchema();
            ActiveRecordStarter.CreateSchema();

            Osoba o = new Osoba
            {
                ImieNazwisko = "Jan Kowalski",
                Adres1 = new Adres
                {
                    Kod = "51-555",
                    Miasto = "Wrocław",
                    Ulica = "ul. Ciasna"
                },
                Adres2 = new Adres
                {
                    Kod = "51-555",
                    Miasto = "Wrocław",
                    Ulica = "ul. Ciasna"
                }
            };
            o.Save();
        }
    }
}
