How about supporting multiple attributes?

2 views
Skip to first unread message

Valeriu Caraulean

unread,
Aug 26, 2008, 6:26:27 AM8/26/08
to Fluent NHibernate
Hi everyone

Just faced this requirement and don't know yet how to do it in the
simplest way.
The mapping that I'd like to map fluently:

<property name="Id2" type="int" generated="always" insert="false" />

This can be easily solved if it would be possible to add two
attributes to PropertyMap. But PropertyMap.SetAttribute() returns
void, so it cannot be chained further.

After a very quick look at the code, one of the solutions will be to
modify IHasAttribute's signature to
public interface IHasAttributes
{
IHasAttributes SetAttribute(string name, string value);
}

Any ideas?

James Gregory

unread,
Aug 26, 2008, 7:29:12 AM8/26/08
to fluent-n...@googlegroups.com
You should be able to get your insert="false" by using AsReadOnly. The generated attribute isn't supported yet, so you'll have to continue to use the SetAttribute for that.

Regarding the void for SetAttribute, that is a bit of a pain. it won't be as simple as just returning IHasAttributes, because that won't let you access the other property mappings. We should be able to solve this through a bit of generic jiggery-pokery.

Valeriu Caraulean

unread,
Aug 26, 2008, 8:40:13 AM8/26/08
to fluent-n...@googlegroups.com

Thanks!

This worked: 

Map(x => x.Number).AsReadOnly().SetAttribute("generated", "always");

Jeremy D. Miller

unread,
Aug 26, 2008, 10:49:47 AM8/26/08
to fluent-n...@googlegroups.com
Or use a "Nested Closure" in the FI to have a full end around for all little one off customizations:

.OverrideMapping(Action< IProperty > action) that returns PropertyMap

or use an anonymous class like the MVC for the name/value properties


 
Jeremy D. Miller
The Shade Tree Developer
jeremy...@yahoo.com

Dru Sellers

unread,
Aug 26, 2008, 10:59:01 AM8/26/08
to fluent-n...@googlegroups.com
IMHO, -1 on the anonymous class
Reply all
Reply to author
Forward
0 new messages