-->
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: How can I find the column native type / max length?
PostPosted: Sun Jun 10, 2007 11:49 am 
Newbie

Joined: Wed Dec 14, 2005 3:29 pm
Posts: 16
I am trying to solve a generic problem of users entering more data on a web form than the column can store (for www.foodcandy.com). I could go through the schema and set some max length property on the control by hand of course, but I'd like to at least automate that or better, make it dynamic.

The first part is iterate through the schema and for each column find out its type, then for each (n)varchar type find out its max length. I can do this in MSSQL looking at the schema, etc., but this makes an assumption that I have a SQL driver. Anyone have any suggestions of how to do this generically in NHibernate?

Here's a start to enumerate objects and get the column names.

Code:
IDictionary metadata = Session.SessionFactory.GetAllClassMetadata();
            foreach (DictionaryEntry entry in metadata)
            {
                Console.WriteLine(entry.Key);
                SingleTableEntityPersister persister = (SingleTableEntityPersister) entry.Value;
                Console.WriteLine(" table: {0}", persister.TableName);
                foreach (string name in persister.PropertyNames)
                {
                    Console.WriteLine("  property: {0}", name);
                    string[] columnnames = persister.GetColumnNames(name);
                    foreach (string columnname in columnnames)
                    {
                        Console.WriteLine("   column: {0}", columnname);
                       
                    }
                }
            }


Thx
dB.


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.