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]
        public Adres Adres { 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",
                Adres = new Adres
                {
                    Kod = "51-555",
                    Miasto = "Wrocław",
                    Ulica = "ul. Ciasna"
                }
            };
            o.Save();
        }
    }
}
