Hello, I'am trying with DataObjects and I have a problem with simplest task.

My code:

namespace Model
  {
      public class Place : Entity
      {
          [Key]
          [Field]
          public int Id { get; private set; }

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

namespace DataObjectsTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var domainConfig = new DomainConfiguration("sqlserver",
                @"Data Source=localhost\SQLEXPRESS;Initial Catalog=DataObjectsTest;Persist Security Info=True;User ID=db;Password=db");
            domainConfig.Types.Register(typeof (Place).Assembly);            
            domainConfig.UpgradeMode = DomainUpgradeMode.Recreate;
            var domain = Domain.Build(domainConfig);
            using (var s = domain.OpenSession())
            {
                s.Activate();
                using (var t = s.OpenTransaction())
                {
                    new Place {Name = "PL1"};
                    t.Complete();
                }
            }
        }
    }
}

And there is an error "Type 'Place' is not registered." at line "new Place {Name = "PL1"};"

I can see that in my database no one domain table was created after Domain.Build but there was not any errors or warnings too.

Only three Metadata tables exists.

DomainConfiguration.Types contains Place type after Register call, but Domain.Model doesnt contains it.

I tried it at last stable release and now I'am trying it with 5 version.

asked Dec 16 '13 at 09:07

Valentin%20Polezhaev's gravatar image

Valentin Polezhaev
7112


One Answer:

Hello Valentin,

I think you're missing [HierarchyRoot] definition on Place type. Only types with this attribute defined and their descendants are considered persistent by DataObjects.Net.

answered Dec 16 '13 at 10:06

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

Thanks, it works. For me it was not obviously and docs look like inheritance from Entity or Structure is enough to declare such types as persistent.

Probably I understand it wrong, but is there a case when entity (Place : Entity) without HierarhcyRootAttribute can be not-persistent? And what is a real practical impact of such types?

(Dec 17 '13 at 03:28) Valentin Polezhaev Valentin%20Polezhaev's gravatar image

This is useful feature if you want to share common implementation between different hierarchies.

For example it's common approach to define base class with key fields, version fields and so on. DataObjects.Net will consider fields defined in such classes.

(Dec 17 '13 at 03:37) Denis Krjuchkov Denis%20Krjuchkov's gravatar image
Your answer
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

powered by OSQA