0

Let's say I've got some fluently configured NHibernate settings, which is using both Fluent mappings and Automappings.

        Configuration = Fluently.Configure()
            .Database(SQLiteConfiguration.Standard.ShowSql().InMemory)
            .Mappings(x =>
                      {
                          x.FluentMappings.AddFromAssemblyOf<RepositoryEntity>();
                          x.AutoMappings.Add(autoPersistenceModel);
                      });

Now - is it possible to check that some arbitrary type T is mapped (or not mapped) to this configuration?

I am attempting to make some bulletproof repository and I think this moment is kind of crucial.

Thank you

2 Answers 2

4

Yes. After creating your SessionFactory, keep the Configuration around, and set up this method in your repository:

public bool IsMapped (Type testType)
{
   return MyConfiguration.ClassMappings.Any(m => m.EntityName == testType.FullName);
}

AFAIK this can be used to detect both fluently- and XML-mapped classes. You may need to compare more closely if you have similarly-named classes in different namespaces, but this should get you started.

Something you may also be able to use in developing a "bulletproof" Repo is the EntityNotFoundDelegate, which allows you to define a custom method for dealing with entities given to a repository for which it doesn't have a mapping. You could, potentially, use this to ask another repository if it can handle the entity, or kick it back to a Strategy pattern that may have several possible repos to try.

Sign up to request clarification or add additional context in comments.

Comments

0

Keith has pretty much answered your question, however for more bulletproofing you could check out the PersistenceSpecification class. (It requires the knowledge of type T though)

http://www.packtpub.com/article/using-fluent-nhibernate-persistence-tester-and-ghostbusters-test

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.