问题
Greeetings, i'm a new to Fluent NHibernate.
Let's imagine, a have a lot of classes
ClassA
ClassB
ClassC
...
After creating schema, i want to get a list of created tables.
For example:
Opening form -> there's a names of the Tables, when we clicking to each one we're getting records from this table.
How can I achieve this? Is there a cheaper way? Is it possible to make without reflection? (Parsing all classes, and gettings it's names)
回答1:
NHiberante has built-in support to get names of all mapped entities and their tables. The code could look like this:
ISessionFactory factory = ... // get your NH ISessionFactory;
// all mapped entities as dictionary
var allClassMetadata = factory.GetAllClassMetadata();
foreach (var meta in allClassMetadata)
{
var persister = meta.Value as NHibernate.Persister.Entity.AbstractEntityPersister;
var tableName = persister.TableName;
var entityName = persister.EntityType.Name;
...
// TODO what needed with this info
}
来源:https://stackoverflow.com/questions/25000215/fluent-nhibernate-questions-about-code-design