本文整理汇总了C#中NHibernate.GetColumnMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# NHibernate.GetColumnMetadata方法的具体用法?C# NHibernate.GetColumnMetadata怎么用?C# NHibernate.GetColumnMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate
的用法示例。
在下文中一共展示了NHibernate.GetColumnMetadata方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetKeyColumns
protected IColumnMetadata[] GetKeyColumns(NHibernate.Dialect.Schema.ITableMetadata tableMetaData)
{
string key = string.Format("PK_{0}.{1}.{2}", tableMetaData.Catalog, tableMetaData.Schema, tableMetaData.Name);
if (currentContext[key] == null)
{
if (currentContext.TableExceptions.HasException(tableMetaData.Name, tableMetaData.Catalog, tableMetaData.Schema))
{
cfg.db2hbmconfTable exc = currentContext.TableExceptions.GetTableException(tableMetaData.Name, tableMetaData.Catalog, tableMetaData.Schema);
if (exc.primarykey != null)
{
if (exc.primarykey.keycolumn != null && exc.primarykey.keycolumn.Length > 0)
{
logger.Info(string.Format("table {0}: using configured primary key def", tableMetaData.Name));
try
{
IColumnMetadata[] res = exc.primarykey.keycolumn.Select(q => tableMetaData.GetColumnMetadata(q.name)).Where(q => q != null).ToArray();
currentContext[key] = res;
return res;
}
catch (Exception e)
{
logger.Error("Can't obtain metadata for configured primary key columns.", e);
throw e;
}
}
}
}
//try to found the primary key from the schema
try
{
var dt = currentContext.Dialect.GetCompleteColumnSchema(currentContext.Connection, tableMetaData.Schema, tableMetaData.Name);
int isKey = dt.Columns.IndexOf(ISKEY);
int colName = dt.Columns.IndexOf(COLNAME);
List<IColumnMetadata> cols = new List<IColumnMetadata>();
foreach (DataRow dr in dt.Rows)
{
if ((bool)dr.ItemArray[isKey])
{
var cmeta = tableMetaData.GetColumnMetadata(dr.ItemArray[colName].ToString());
if( null != cmeta )
cols.Add(cmeta);
}
}
currentContext[key] = cols.ToArray();
return currentContext[key] as IColumnMetadata[];
}
catch (Exception e)
{
logger.Error("Can't obtain primary key metadata from schema.If database does not support key schema information, please consider to use configuration in order to provide keys", e);
throw e;
}
}
else
{
return currentContext[key] as IColumnMetadata[];
}
}