Geeks With Blogs
Liam McLennan hackingon.net

The usual starting point for automapping is to tell NHibernate to map all of the types from a particular assembly. From there we may filter the set of types that are mapped by providing a predicate. The common pattern looks something like this:

AutoPersistenceModel.MapEntitiesFromAssemblyOf<Post>()
.Where(type => type.Namespace == "Acme.Domain");

If we want to exclude a particular type within the namespace that is easy:

AutoPersistenceModel.MapEntitiesFromAssemblyOf<Post>()
.Where(type => type.Namespace == "Acme.Domain" 
&& type.Name != "NotAPersistentEntity");

However, if the type to be excluded is an open generic type then you have to use the CLR generic type notation, which is the type name followed by `N, where N is the number of type parameters. To exclude an open generic type MyCustomCollection<T>:

AutoPersistenceModel.MapEntitiesFromAssemblyOf<Post>()
.Where(type => type.Namespace == "Acme.Domain"
&& type.Name != "MyCustomCollection`1");
Posted on Monday, August 30, 2010 4:03 PM | Back to top

Copyright © Liam McLennan | Powered by: GeeksWithBlogs.net