regarding the "if I need to touch 2 places, something is wrong", I
still can't believe Ayende said that, especially because I know he
uses R#. I've been using fluent nhibernate for some time and even
though it has one or two bugs, I can't really count the number of ways
it has helped me maintain the mapping consistency between my classes
and my tables. The biggest problem most people face with the
traditional mapping xml files is that refactoring isn't supported
there (ok, there was a r# plugin that was supposed to do that, but I
think it never worked out very well). With fluent nhibernate, for
instance, I can only do a simple renaming on a property and know that
it will be propagated onto the mappings. And as Billy said, you can
put the mappings on your repository assembly and you'll still have
POCO. That won't happen with attributes...
One more thing regarding validation: even though I still haven't
looked at nhibernator validator, I'm positive that validation is
really a concrete domain aspect and I'm a believer that it should be
put inside the domain base assembly. What I'm saying is that it is
possible to add some basic core interfaces and base classes for
validation and they should be inside the core assembly and know
nothing about any data access details (ok, I haven't looked at the
last bits, so I don't know how validation was added to it. what I',
proposing is adding some sort of methods that would do 2 things: give
broken validation rules and give the broken rules when an object would
be transitioning from the current state to an hipotetical future
state)...
--
Regards,
Luis Abreu
i think that won't be problematic...what nh is doing is escaping the
name to make sure that it's not using any sql reserved term (putting
[] will "escape" the word you're using).
I've noticed that I've performed some changes on the mappings and I've
ended up using integers. Here's my code:
HasMany<Contact>(branch => branch.Contacts)
.AsSet()
.WithTableName("Contactos")
.WithKeyColumn("IdFilial")
.Component(ct =>
{
ct.Map(c => c.Kind, "TipoContacto")
.CustomTypeIs(typeof (ContactKind))
.CustomSqlTypeIs("integer");
ct.Map(c => c.Value, "Contacto");
});
Where:
ContactKind is the enumeration
CustomSqlTypeIs is the sql type on th bd.
See if this works for you. if it doesn't, you can always set the
CustomTypeIs to Int32 and it should work without any problems.
--
Regards,
Luis Abreu
Yes, I'm not discussing which way is better. Personally, I prefer to have
POCO, but that's my opinion only. There's probably nothing wrong with tying
the properties/fields to table fields through attributes. As I've said, I do
prefer POCOs and in this case, I do see some advantages on using fluent NH.
However, if you don't want to go with POCOs, then there really isn't much I
have to say about the way you set up the relationships...
What I'm saying is that it's not DDD. If you really look at a well modeled
DDD app, you'll notice that you tend to have lots of methods used for
interacting with objects (and that's natural because methods tend to be more
"descriptive" than properties and one of the main objectives of DDD is
having a model which is easily understood by everyone that knows the
ubiquitous language of that domain). Ok, so do I use properties/fields? Yes,
I do that and NH is configured for loading them from the database, but the
difference is that on my domain, most interactions are not done through
properties, but through method calls.
Luis
>
> I really can't see why using this approach for mapping is no DDD, and
> I why decorating objects with attributes makes them less POCO. The
No, no, no, that's not what I'm saying:) (mapping with attribs is not DDD).
Regarding the POCO, adding the attributes means that your objects end up
"knowing" details about the db and you end up adding an unnecessary
reference to the active record assembly (at least, that is what happens when
you use attributes with NH). With the xml file or NH fluent that doesn't
need to happen because you can build your domain assembly without any
references to NH assemblies (ok, not sure if that is true with the current
version of this framework, but I think it should be). Having said this, if
you don't want to use POCO, there's nothing wrong with the attributes...
Luis
good :)
> As for POCO, well, not linking the domain objects library to some
> external framework references is something I don't believe we can ever
> achieve, unless we're working with very simple objects. The need for
> validation is the first thing that comes to my mind, and things like
> DomainSignature, for example, are very useful and I think that
> outweighs the problems of referring a few external libraries.
validation is easy achievable with inversion of control, though most
guys will not go that far. As I've said, it all depends on what you
want: if you don't mind having those dependencies, then there's
nothing wrong with the attributes :)
> On the other hand, adding another class to do the mapping obscures the
> code, makes us search basic informations about our model in two
> different places, and that's something that I qualify as much more
> important than linking one or two external libraries, and in the case
> o ActiveRecord you don't need to reference NHibernate's.
I disagree. Persistence information is a detail...important, but not a
domain detail, and that's why I don't think it's important that you
don't put that kind of info on the domain. There's a detail here: you
keep mentioning databases, but is that really important when you
tjhink about domain driven design? I know there are several guys out
there which don't use databases for storing the domain objects and
I'll be trying to use that approach in my work. to make that happen, I
really want my objects to be persistent ignorant and that means no
attributes or any db info on my domain model...
> As for DB implementation details, if you build your objects correctly
> and makes your DB schema comply to your objects structure, not the
> other way around, you won't need to give any details about
> implementation on the attributes, just make explicit the logical
> relationships, which will make the code clearer. For example, if you
> have all your tables named after the objects and all table's fields
> name after your objects properties, them you don't need to specify the
> implementation name in the attributes. But if you have an object named
To me the db is a detail related with storage. I don't really care
about the table structure and I will always build the database from
the object model I have in my domain (not the other way around)...
--
Regards,
Luis Abreu
Agreed...that's why I keep insisting in having some sort of base classes on
the domain for validation. I'd prefer a library without any dependencies on
OR/Ms, but again, I'm just giving my opinion...
> > As for referring to databases, well, 90% of all domain objects will
> be
> > persisted to a RDBMS
>
> Not true. I'm working on a project that persists objects remotely
> using web services.
And, as I've said, I've also seen several guys which resort to serialization
to disk with some great results...I do agree that DBs are common though, but
when you think about DDD, they're not that important by themselves...
> I agree. POCO is not a goal by itself by a way to achieve domain
> purity. but i think for practicle reason we need to use libraries to
> perform common tasks needed by the domain such as domain validation,
> equality and hash key calculation, etc.
>
> My comment on the whole subject is I think if you're using a database
> then mapping to the database has to happen somewhere. in the case of
> active record they happen in the domain object which i think is wrong
> because of the reasons mentioned already. in the case of fluent
> nhibernate it happens outside the domain where they should be and
> they're verified at compile time which gives them an advantage over
> xml mapping.
>
Agreed....
Luis