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.
Here's the database access logic.
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 |
Hello Kirill, First of all you need to make Pet and Person public. If you don't declare them as public explicitly they will be treated by compiler as private classes. As you probably know private classes aren't usable by other assemblies. Also you need to mark Pet and Person by [HierarchyRootAttribute]. This attribute declares the root of the types hierarchy. Hierarchy roots and all types derived from them will be represented in database as tables, they also can be used in Session.Query.All<t>() for querying data from database. Types which are not in some hierarchy won't be included in domain. For example,
If you register these types then after domain building is finished you will have tables - Pet(Id, CreationDate, Name) and Dog(Id, TypeOfDog). SomeBaseEntity won't be represented as a table. But as you can see all its field will be in Pet. You can query all pets(if you have not only dogs) or dogs specifically
Another examle,
I just moved [HierarchyRoot] from Pet to SomeBaseEntity class. In this case, you will have three tables - SomeBaseEntity(Id, CreationDate), Pet(Id, Name) and Dog(Id, TypeOfDog) so I can do this
DomainConfiguration.Types property represents all registered-to-process types. If you register an assembly you will see all the accessible types of the assembly in DomainConfiguration.Types, but they might be not included in domain. When domain is built you can also check persistent types which were included in domain in Domain.Model.Types. This collection has groups of elements like Entities, Structures, Interfaces. You don't need to register one assembly twice. Pet and Person are in the same assembly, right? |