Fluent NHibernate, questions about code design

拟墨画扇 提交于 2019-12-08 12:39:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!