I'm just a junior developer, so please don't judje hard. I started implement my solution by declaring classes that will represent my dbase records.

namespace OrmObj
{
    class Person : Entity
    {
        [Key, Field]
        public int Id { get; private set; }

        [Field]
        public string Name { get; set; }

        [Field]
        public int Age { get; set; }

        [Field]
        public EntitySet<Pet> Pets { get; set; }

        public override string ToString()
        {
            return String.Format("I'm {0} {1} yers old, I have {2} pets", this.Name, this.Age, this.Pets.Count);
        }

        public Person(Session session, string name, int age) : base(session)
        {
            this.Name = name;
            this.Age = age;
        }

        public Person(Session session) : this(session, "Anonimus", 25)
        {
        }
    }

    class Pet : Entity
    {
        [Key, Field]
        public int Id { get; private set; }

        [Field]
        public string Name { get; set; }

        [Field]
        public int Age { get; set; }

        public Pet(Session session, string name, int age) : base(session)
        {
            this.Name = name;
            this.Age = age;
        }

        public Pet(Session session) : this(session, "Unknown", 5)
        {
        }

    }

}

Here's the database access logic.

private static string magicOne = "Data Source=localhost; Initial Catalog=DataObjectsTest;MultipleActiveResultSets=True;User Id=sa;Password=sa";
private static string sqlserver = "sqlserver";

static void Main(string[] args)
{
    var config = new DomainConfiguration(sqlserver, magicOne);
    config.Types.Register(typeof(Person).Assembly);
    config.Types.Register(typeof(Pet).Assembly);
    var domain = Domain.Build(config);
    using (var session = domain.OpenSession())
    {
        using (var txact = session.OpenTransaction())
            {
                var cat1 = new Pet(session, "Cake", 3);
                var cat2 = new Pet(session, "Fiona", 5);
                var person = new Person(session, "Eric", 42);

                person.Pets.Add(cat1);
                person.Pets.Add(cat2);

                txact.Complete();
            }
    }

}

I cought "Type 'Pet' is not registered." exception. And that is strange becouse I definitely can see my Pet and Person classes registered in config variable

asked Jul 12 at 06:52

Kirill's gravatar image

Kirill
52

edited Jul 12 at 06:55

Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×3

Asked: Jul 12 at 06:52

Seen: 214 times

Last updated: Jul 12 at 06:55

powered by OSQA