功能NHibernate,有关代码的设计问题 [英] Fluent NHibernate, questions about code design
问题描述
Greeetings,我是一个新功能NHibernate。
Greeetings, i'm a new to Fluent NHibernate.
让我们想象一下,一个有很多类
Let's imagine, a have a lot of classes
ClassA的结果
ClassB的结果
ClassC结果
...
ClassA
ClassB
ClassC
...
创建模式后,我。想获得创建表的列表
After creating schema, i want to get a list of created tables.
例如:
打开表 - >还有一个名字表中,当我们点击到每一个我们从该表中获取的记录。
Opening form -> there's a names of the Tables, when we clicking to each one we're getting records from this table.
我怎样才能做到这一点?有没有便宜的方式?
是有可能使不反思?的(解析所有类,并gettings它的名称)的
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)
推荐答案
NHiberante有内置的支持,以获得所有映射实体及其表的名称。代码可以是这样的:
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
}
这篇关于功能NHibernate,有关代码的设计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!