These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HELP! How to get type of mapped class at runtime??
PostPosted: Mon Apr 09, 2007 6:02 pm 
Beginner
Beginner

Joined: Thu Oct 19, 2006 1:03 pm
Posts: 29
I'm writing a small class that reads assemblies and generates tables for them.

Why? Because my main configuration file passed to hbm2ddl would regenerate all tables, and I want it preferably on a per-mapped-class granularity.

Anyhow, this is part of what I've got:
Code:
/// <summary>
/// Checks whether the tables in the <see cref="NHibernate.Cfg.Configuration"/> file exist.
/// </summary>
/// <param name="config">The configuration file to test.</param>
/// <returns>Whether the tables corresponding to the passed configuration file exist.</returns>
private static bool doesTableExist(Configuration config)
{
   ISessionFactory factory = config.BuildSessionFactory();
   using (ISession session = factory.OpenSession())
   {
      // Let's just try to find one object with the session and be happy.
      ICriteria crit;

      // I could use GetClassMetaData here instead, create a new config
      // and then generate that table if no results were found, to make it
      // MUCH more granular. But one step at a time.
      IDictionary classMetaData = factory.GetAllClassMetadata();

      foreach (object key in classMetaData.Keys)
      {
         crit = session.CreateCriteria(classMetaData [key].ClassType);

         // So if the listing doesn't contain any results,
         // tables don't exist, or it just doesn't matter if I redo the table.
         if (crit.List().Count == 0)
            return false;
      }
      
   }
   return true;
}


I need help with the first part of the foreach loop. Obviously it's wrong, but I can't find documentation on what the IDictionary that's returned contains, so I don't know what to do with it.

Could someone help me with this, or perhaps should me a more effective way of doing the same thing?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.