views:

194

answers:

2

Hi, I'm using NHibernate with my ASP.Net MVC application. I'm writing some extensions (plugins) for my application. And I'm loading those plugin dynamically (from different assemblies). In my base application I have many entities and mappings defined (User, Group, etc...)

I need to create new entities in my extensions, so i.e. I'm creating News module, so I need to create News mapping. In database News table has a foreign key to User table. Is there any way I can modify my User mapping, so it will have:

HasMany(x => x.News)
  .KeyColumn("UserId")
  .Inverse();

Or the only way to do it is to change code in my User class and recompile project ?

I'm not NHibernate advanced user, so any help will be appreciated. TIA.

+1  A: 

Fluent NHibernate might help

Check the sections on Fluent Mapping or, even better, Auto Mapping

The Auto Mapping can be overridden for individual properties if you can't use the default. Also, with fluent NHibernate, you can specify your own defaults for primary keys, foreign keys and the like.

Jason Watts
+1. I know automapping, but how can I add News property to User class ?
Jarek
A: 

You can automap multiple assemblies, e.g.

AutoMap.Assemblies(Assembly.GetExecutingAssembly(), 
                   typeof(MyType).Assembly)

will map the executing assembly, and the assembly that contains "MyType".

Note that this is a relatively new feature (Feb 19, 2010) in FNH, so make sure you have a recent build.

Not sure how this would work in a dynamic loading situation, but I think that's more of an issue with how you would get the list of assemblies (via reflection, probably) than NHibernate per se.

Tom Bushell