Just a quick question for those more familiar with FluentNHibernate. I’ve read the quick start things, and the docs on their site, but am still a tad off. Are the following maps correct, in terms of the HasOne / HasMany relationships? If not, please correct them, and give me reasons, so I better understand. Thanks!
public class CategoryMap : ClassMap<Category>
{
public CategoryMap()
{
Id(x => x.Id);
Map(x => x.Sequence);
Map(x => x.Title);
Map(x => x.Description);
Map(x => x.Enabled);
Map(x => x.Visible);
HasMany(x => x.Forums).Access.CamelCaseField().Cascade.All().Inverse();
}
}
public class ForumMap : ClassMap<Forum>
{
public ForumMap()
{
Id(x => x.Id);
Map(x => x.Sequence);
Map(x => x.Title);
Map(x => x.Description);
Map(x => x.ThreadsEnabled);
Map(x => x.ThreadsQueued);
Map(x => x.RepliesEnabled);
Map(x => x.RepliesQueued);
Map(x => x.Enabled);
Map(x => x.Visible);
HasOne(x => x.Category).Access.CamelCaseField().Cascade.All();
}
}
P.S. These will eventually go into a convention file, but for now, I just need to know how to code relationships period.
Don’t use the HasOne mapping http://wiki.fluentnhibernate.org/Fluent_mapping#HasOne_.2F_one-to-one.
Use References()
That link links to a blog post by James Gregory (primary dev on FluentNHibernate) with a good explanation.
PS. I would try and get used to the AutoMap, works for better and the convention system is sweet 
I took your advice and looked at how SharpArchitecture set it up. I now have a Mapping.Conventions namespace and an AutoPersistenceModelGenerator class. No more ClassMaps. I finally got it working thanks to that, and your suggestion.
I still have a few things left to look at before I call my architecture complete. I look forward to your input on those.
I’ll start with this:
I have AutoMapper set up using configuration interface in a boostrap class. What I’ve done is mapped, bi-directionally, viewmodels and entities:
Mapper.CreateMap<Category, CategoryViewModel>();
Mapper.CreateMap<CategoryViewModel, Category>();
The reason I did so is that it should make updating an entity from a model easier:
Category entity = categoryRepository.Get(model.Id);
entity = Mapper.Map<CategoryViewModel, Category[FONT=Consolas][SIZE=2]>(model);
categoryRepository.SaveOrUpdate(entity);
[/SIZE][/FONT]I haven’t tested this yet, but I can see one problem. The base Entity class has the Id field set to protected set. Will the mapper just skip this field? What’s the best way to do this?