Newbie Question

25 views
Skip to first unread message

Swampy

unread,
Apr 13, 2009, 11:19:56 PM4/13/09
to Fluent NHibernate
I have seen several posts asking this question, but, I am not sure
that I have seen an answer.

My Entities are split among several classes, but, I need to be able to
query on them. Is there a way to use AutoPersistenceModel to include
these files?

For example, if I have Product and Category in separate assemblies.I
thought I might be able to use:
var autoMappings =
AutoPersistenceModel
.MapEntitiesFromAssemblyOf<Category>()
.MergeWithAutoMapsFromAssemblyOf<Product>()
.WithSetup(s => s.IsBaseType = type => type == typeof
(BaseEntity))
.ConventionDiscovery.AddFromAssemblyOf<PluralizeTableNameConvention>
()

I don't understand the purpose of "MergeWithAutoMapsFromAssembly"

Please, any help, guidance or just a point in the right direction
would be helpful!!

Chuck

Hudson Akridge

unread,
Apr 15, 2009, 1:00:47 AM4/15/09
to fluent-n...@googlegroups.com
Disclaimer: I don't have a ton of practical Automapping experience, as I have no need to use it in my day to day activities.

You're asking two questions here, and I'm not sure if they're related to the same problem. 
1.) Are you having a problem with the "MergeWithAutoMapsFromAssembly" call? Could you briefly explain how you're expecting it to work in your environment? That method name might be misleading, from what I can tell during my investigations (and I could be wrong here), that call does not actually automap the assembly you're referencing. It simply adds that assemblies ClassMap<T> types to the current AutoPersistenceModel.
2.) You state your entities are split among several classes. In what way? Could you provide a simplified class data definition for some of the classes you're attempting to search on and an example of the search you're attempting to perform?

Chuck

unread,
Apr 15, 2009, 6:25:36 AM4/15/09
to Fluent NHibernate
Hudson -

Thanks for responding.

Essentially, I have two class libraries with DTO's in them. To
illustrate, I have created a simple mapping exercise against
Northwind, having to Clas libraries with one class each: Cateogry in
one, product in the other. Fluent Configuration is:

ISessionFactory sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString
(c => c.Is(@"Data Source=.\sqlexpress;Initial
Catalog=Northwind;Integrated Security=True")).ShowSql())
.Mappings(m => m.AutoMappings.Add(
AutoPersistenceModel.MapEntitiesFromAssemblyOf<Product>()
.AutoMap<Category>()
.WithSetup(s => s.IsBaseType = type => type == typeof
(BaseEntity))
.Where(type => type.IsSubclassOf(typeof(BaseEntity)))
.ConventionDiscovery.AddFromAssemblyOf<PluralizeTableNameConvention>)
).BuildSessionFactory();

The AutoMap<Cateogry> after the MapEntitesFromAssemblyOf<Product> will
produce the desired mappings, and gives me a desired reference between
Category and Product (via an IList<Product> Products property in
category).

What I was hoping was instead of using AutoMap<Category> (moving
beyond the simple exercise, there could be MANY AutoMap<> appended), I
could use something similar to MapEntitesFromAssemblyOf<Product>, but
for the Category assembly. I have also played with this:

Fluently.Configure()
.Mappings(m =>
{
m.AutoMappings.Add(new AutoPersistenceModel(typeof
(Category).assembly));
m.AutoMappings.Add(new AutoPersistenceModel(typeof
(Product).assembly));
});

But was not getting it to work.

Again, thanks for the feedback and any pointers.

Cheers!

C
> > Chuck- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages