本文整理汇总了C#中NHibernate.Cfg.Configuration.GetClassMapping方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.GetClassMapping方法的具体用法?C# Configuration.GetClassMapping怎么用?C# Configuration.GetClassMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.GetClassMapping方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AllInOne
public void AllInOne()
{
Configuration cfg = new Configuration();
cfg.AddResource(BaseForMappings + "Extendshbm.allinone.hbm.xml", typeof(ExtendsFixture).Assembly);
Assert.That(cfg.GetClassMapping(typeof (Customer).FullName), Is.Not.Null);
Assert.That(cfg.GetClassMapping(typeof(Person).FullName), Is.Not.Null);
Assert.That(cfg.GetClassMapping(typeof(Employee).FullName), Is.Not.Null);
}
示例2: IncrementGeneratorShouldIncludeClassLevelSchemaWhenGettingNextId
public void IncrementGeneratorShouldIncludeClassLevelSchemaWhenGettingNextId()
{
System.Type thisType = GetType();
Assembly thisAssembly = thisType.Assembly;
Configuration cfg = new Configuration();
cfg.AddResource(thisType.Namespace + ".Mappings.hbm.xml", thisAssembly);
PersistentClass persistentClass = cfg.GetClassMapping(typeof(TestNH1061));
// We know the ID generator is an IncrementGenerator. The dialect does
// not play a big role here, so just use the MsSql2000Dialect.
IncrementGenerator generator =
(IncrementGenerator)
persistentClass.Identifier.CreateIdentifierGenerator(new Dialect.MsSql2000Dialect(), null, null, null);
// I could not find a good seam to crack to test this.
// This is not ideal as we are reflecting into a private variable to test.
// On the other hand, the IncrementGenerator is rather stable, so I don't
// think this would be a huge problem.
// Having said that, if someone sees this and have a better idea to test,
// please feel free to change it.
FieldInfo sqlFieldInfo = generator.GetType().GetField("sql", BindingFlags.NonPublic | BindingFlags.Instance);
string sql = (string)sqlFieldInfo.GetValue(generator);
Assert.AreEqual("select max(Id) from test.TestNH1061", sql);
}
示例3: NHibernateTypeDescriptor
public NHibernateTypeDescriptor(Type entityType, ICustomTypeDescriptor parent,
Configuration nhibernateConfiguration, Type metaDataType)
: base(parent)
{
Type metaDataType1 = metaDataType;
while (entityType != null && entityType.Name.EndsWith("Proxy") &&
entityType.Assembly.GetName().Name.EndsWith("ProxyAssembly"))
entityType = entityType.BaseType;
this.entityType = entityType;
this._nhibernateConfiguration = nhibernateConfiguration;
_classMetadata = nhibernateConfiguration.GetClassMapping(this.entityType);
_identifierCols = _classMetadata.Identifier.ColumnIterator;
if (metaDataType1 != null)
{
var memberInfos =
metaDataType1.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
foreach (var memberInfo in memberInfos)
{
var attributes = memberInfo.GetCustomAttributes(false).Cast<Attribute>();
if (attributes.Any())
_metaDataAttributes.Add(memberInfo.Name, attributes);
}
}
}
示例4: NwaitingForSuper
public void NwaitingForSuper()
{
Configuration cfg = new Configuration();
cfg.AddResource(BaseForMappings + "Extendshbm.Customer.hbm.xml", typeof (ExtendsFixture).Assembly);
Assert.That(cfg.GetClassMapping(typeof (Customer).FullName), Is.Null, "cannot be in the configuration yet!");
cfg.AddResource(BaseForMappings + "Extendshbm.Employee.hbm.xml", typeof (ExtendsFixture).Assembly);
Assert.That(cfg.GetClassMapping(typeof (Employee).FullName), Is.Null, "cannot be in the configuration yet!");
cfg.AddResource(BaseForMappings + "Extendshbm.Person.hbm.xml", typeof (ExtendsFixture).Assembly);
cfg.BuildMappings();
Assert.That(cfg.GetClassMapping(typeof (Customer).FullName), Is.Not.Null);
Assert.That(cfg.GetClassMapping(typeof (Person).FullName), Is.Not.Null);
Assert.That(cfg.GetClassMapping(typeof (Employee).FullName), Is.Not.Null);
}
示例5: ForeignKeyInfo
internal ForeignKeyInfo(Table table, ForeignKey fk, Configuration config)
: base("FK_", table.Name, fk.ColumnIterator, null)
{
//note: the fk object has a ReferencedTable property, but it doesn't always seem to be set
//the reference class property is always set, so we use it instead to get the referenced table
Table referencedTable = config.GetClassMapping(fk.ReferencedEntityName).Table;
_referencedTable = referencedTable.Name;
_referencedColumns = CollectionUtils.Map<Column, string>(
referencedTable.PrimaryKey.ColumnIterator,
delegate(Column column) { return column.Name; });
}
示例6: Process
public void Process(string name, Configuration nhConfig)
{
foreach (var file in GetMappingFiles())
{
nhConfig.AddFile(file);
// HBM.XML file must be named to match entity-name.
var entityName = file.Name.Replace(".hbm.xml", string.Empty);
var nhMappingInfo = nhConfig.GetClassMapping(entityName);
var entityDefinition = definitionCreator.CreateFrom(nhMappingInfo);
definitionProvider.Add(entityDefinition);
}
}
示例7: ConfigureCacheOfCollectionWithOutEntity
public void ConfigureCacheOfCollectionWithOutEntity()
{
Configuration configure = new Configuration().Configure();
configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
configure.EntityCache<EntityToCache>(ce => ce.Collection(e => e.Elements, cc =>
{
cc.RegionName = "MyCollectionRegion";
cc.Strategy =
EntityCacheUsage.NonStrictReadWrite;
}));
var pc = (RootClass) configure.GetClassMapping(typeof (EntityToCache));
Assert.That(pc.CacheConcurrencyStrategy, Is.Null);
}
示例8: ConfigureCacheOfClass
public void ConfigureCacheOfClass()
{
Configuration configure = new Configuration().Configure();
configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
configure.EntityCache<EntityToCache>(ce =>
{
ce.Strategy = EntityCacheUsage.NonStrictReadWrite;
ce.RegionName = "MyRegion";
});
var pc = (RootClass) configure.GetClassMapping(typeof (EntityToCache));
Assert.That(pc.CacheConcurrencyStrategy,
Is.EqualTo(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite)));
Assert.That(pc.CacheRegionName, Is.EqualTo("MyRegion"));
}
示例9: MissingSuper
public void MissingSuper()
{
Configuration cfg = new Configuration();
try
{
cfg.AddResource(BaseForMappings + "Extendshbm.Customer.hbm.xml", typeof (ExtendsFixture).Assembly);
Assert.That(cfg.GetClassMapping(typeof (Customer).FullName), Is.Null, "cannot be in the configuration yet!");
cfg.AddResource(BaseForMappings + "Extendshbm.Employee.hbm.xml", typeof (ExtendsFixture).Assembly);
cfg.BuildSessionFactory();
Assert.Fail("Should not be able to build sessionfactory without a Person");
}
catch (HibernateException) {}
}
示例10: EntityNamesWithPackageFailureExpectedDiffFiles
public void EntityNamesWithPackageFailureExpectedDiffFiles()
{
Configuration cfg = new Configuration();
cfg.AddResource(BaseForMappings + "Extendshbm.packageentitynamesf1.hbm.xml", typeof(ExtendsFixture).Assembly);
cfg.AddResource(BaseForMappings + "Extendshbm.packageentitynamesf2.hbm.xml", typeof(ExtendsFixture).Assembly);
cfg.BuildMappings();
Assert.That(cfg.GetClassMapping("EntityHasName"), Is.Not.Null);
Assert.That(cfg.GetClassMapping("EntityCompany"), Is.Not.Null);
}
示例11: AbstractCollectionPersister
public AbstractCollectionPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, Configuration cfg,
ISessionFactoryImplementor factory)
{
this.factory = factory;
this.cache = cache;
if (factory.Settings.IsStructuredCacheEntriesEnabled)
{
cacheEntryStructure = collection.IsMap
? (ICacheEntryStructure) new StructuredMapCacheEntry()
: (ICacheEntryStructure) new StructuredCollectionCacheEntry();
}
else
{
cacheEntryStructure = new UnstructuredCacheEntry();
}
dialect = factory.Dialect;
sqlExceptionConverter = factory.SQLExceptionConverter;
collectionType = collection.CollectionType;
role = collection.Role;
entityName = collection.OwnerEntityName;
ownerPersister = factory.GetEntityPersister(entityName);
queryLoaderName = collection.LoaderName;
nodeName = collection.NodeName;
isMutable = collection.IsMutable;
Table table = collection.CollectionTable;
fetchMode = collection.Element.FetchMode;
elementType = collection.Element.Type;
isPrimitiveArray = collection.IsPrimitiveArray;
isArray = collection.IsArray;
subselectLoadable = collection.IsSubselectLoadable;
qualifiedTableName = table.GetQualifiedName(dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
int spacesSize = 1 + collection.SynchronizedTables.Count;
spaces = new string[spacesSize];
int ispa = 0;
spaces[ispa++] = qualifiedTableName;
foreach (string s in collection.SynchronizedTables)
{
spaces[ispa++] = s;
}
sqlOrderByString = collection.OrderBy;
hasOrder = sqlOrderByString != null;
sqlOrderByStringTemplate = hasOrder
? Template.RenderOrderByStringTemplate(sqlOrderByString, dialect,
factory.SQLFunctionRegistry)
: null;
sqlWhereString = !string.IsNullOrEmpty(collection.Where) ? '(' + collection.Where + ')' : null;
hasWhere = sqlWhereString != null;
sqlWhereStringTemplate = hasWhere
? Template.RenderWhereStringTemplate(sqlWhereString, dialect, factory.SQLFunctionRegistry)
: null;
hasOrphanDelete = collection.HasOrphanDelete;
int batch = collection.BatchSize;
if (batch == -1)
{
batch = factory.Settings.DefaultBatchFetchSize;
}
batchSize = batch;
isVersioned = collection.IsOptimisticLocked;
keyType = collection.Key.Type;
int keySpan = collection.Key.ColumnSpan;
keyColumnNames = new string[keySpan];
keyColumnAliases = new string[keySpan];
int k = 0;
foreach (Column col in collection.Key.ColumnIterator)
{
keyColumnNames[k] = col.GetQuotedName(dialect);
keyColumnAliases[k] = col.GetAlias(dialect);
k++;
}
ISet distinctColumns = new HashedSet();
CheckColumnDuplication(distinctColumns, collection.Key.ColumnIterator);
#region Element
IValue element = collection.Element;
if (!collection.IsOneToMany)
{
CheckColumnDuplication(distinctColumns, element.ColumnIterator);
}
string elemNode = collection.ElementNodeName;
if (elementType.IsEntityType)
{
string _entityName = ((EntityType) elementType).GetAssociatedEntityName();
elementPersister = factory.GetEntityPersister(_entityName);
if (elemNode == null)
{
elemNode = cfg.GetClassMapping(_entityName).NodeName;
}
// NativeSQL: collect element column and auto-aliases
}
else
{
elementPersister = null;
//.........这里部分代码省略.........
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:101,代码来源:AbstractCollectionPersister.cs
示例12: JoinedSubclassAndEntityNamesOnly
public void JoinedSubclassAndEntityNamesOnly()
{
Configuration cfg = new Configuration();
cfg.AddResource(BaseForMappings + "Extendshbm.entitynames.hbm.xml", typeof (ExtendsFixture).Assembly);
cfg.BuildMappings();
Assert.That(cfg.GetClassMapping("EntityHasName"), Is.Not.Null);
Assert.That(cfg.GetClassMapping("EntityCompany"), Is.Not.Null);
}
示例13: UnionSubclass
public void UnionSubclass()
{
Configuration cfg = new Configuration();
cfg.AddResource(BaseForMappings + "Extendshbm.unionsubclass.hbm.xml", typeof (ExtendsFixture).Assembly);
cfg.BuildMappings();
Assert.That(cfg.GetClassMapping(typeof (Person).FullName), Is.Not.Null);
Assert.That(cfg.GetClassMapping(typeof (Customer).FullName), Is.Not.Null);
}
示例14: GetDirectoryProviderName
private static string GetDirectoryProviderName(System.Type clazz, Configuration cfg)
{
// Get the most specialized (ie subclass > superclass) non default index name
// If none extract the name from the most generic (superclass > subclass) [Indexed] class in the hierarchy
PersistentClass pc = cfg.GetClassMapping(clazz);
System.Type rootIndex = null;
do
{
IndexedAttribute indexAnn = AttributeUtil.GetIndexed(pc.MappedClass);
if (indexAnn != null)
{
if (string.IsNullOrEmpty(indexAnn.Index) == false)
{
return indexAnn.Index;
}
rootIndex = pc.MappedClass;
}
pc = pc.Superclass;
} while (pc != null);
// there is nobody out there with a non default [Indexed(Index = "fo")]
if (rootIndex != null)
{
return rootIndex.Name;
}
throw new HibernateException("Trying to extract the index name from a non @Indexed class: " + clazz);
}
示例15: AddAnnotations
private static void AddAnnotations(Configuration configuration, SrmSettings settings, AnnotationDef.AnnotationTarget annotationTarget, Type persistentClass)
{
var mapping = configuration.GetClassMapping(persistentClass);
foreach (var annotationDef in settings.DataSettings.AnnotationDefs)
{
if (!annotationDef.AnnotationTargets.Contains(annotationTarget))
{
continue;
}
string columnName = AnnotationDef.GetColumnName(annotationDef.Name);
Type accessorType;
switch (annotationDef.Type)
{
case AnnotationDef.AnnotationType.number:
accessorType = typeof (NumberAnnotationPropertyAccessor);
break;
case AnnotationDef.AnnotationType.true_false:
accessorType = typeof (BoolAnnotationPropertyAccessor);
break;
default:
accessorType = typeof (AnnotationPropertyAccessor);
break;
}
AddColumn(mapping, columnName, accessorType);
}
}