NHibernate: how to get the displayed values?

Suppose I have a Customer class that is mapped to a database, and everything is fine.

Now suppose I want - in my application - the column name that NH knows Customer.FirstName matches.

How should I do it?

+3
source share
2 answers

You can access the database field name through NHibernate.Cfg.Configuration:

// cfg is NHibernate.Cfg.Configuration
// You will have to provide the complete namespace for Customer
var persistentClass = cfg.GetClassMapping(typeof(Customer));
var property = persistentClass.GetProperty("FirstName");
var columnIterator = property.ColumnIterator;

The property ColumnIteratorreturns IEnumerable<NHibernate.Mapping.ISelectable>. In almost all cases, properties are displayed in a single column, so the column name can be found with property.ColumnInterator.ElementAt(0).Text.

+5
source

I do not know that this is doable.

, XML , . API, hibernate (pardon the lingo Java) , .

: Jamie, NHibernate Hibernate API, Hibernate org.hibernate.Hibernate "" .

0

Source: https://habr.com/ru/post/1737538/


All Articles