本文整理汇总了C#中NHibernate.Cfg.Configuration.AddResource方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.AddResource方法的具体用法?C# Configuration.AddResource怎么用?C# Configuration.AddResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.AddResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureNHibernate
protected virtual void ConfigureNHibernate()
{
var configuration = new Configuration()
.SetProperties(new Dictionary<string, string>
{
{Environment.Dialect, typeof (MsSql2005Dialect).AssemblyQualifiedName},
{Environment.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName},
{Environment.ConnectionString, RootContext.GetConnectionStringFor(TenantId)},
});
var customMapping = GetMappingFrom(Assembly);
var added = new HashSet<string>();
foreach (var mapping in customMapping)
{
configuration.AddResource(mapping, Assembly);
added.Add(GetEntityName(mapping));
}
var coreMapping = GetMappingFrom(typeof(AbstractBootStrapper).Assembly);
foreach (var mapping in coreMapping)
{
if (added.Add(GetEntityName(mapping)) == false)
continue;//already there
configuration.AddResource(mapping, typeof (AbstractBootStrapper).Assembly);
}
container.Kernel.AddComponentInstance<Configuration>(configuration);
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
container.Kernel.AddComponentInstance<ISessionFactory>(sessionFactory);
}
示例2: Connect
public static void Connect()
{
ServerConsole.WriteLine("Database connecting...", MessageLevel.ODBC);
//create config
ServerConsole.WriteLine("Connecting to KalAuth...", MessageLevel.ODBC);
Configuration cfg = new Configuration().Configure("kalauth.cfg.xml");
//load resources
ServerConsole.WriteLine("Loading resources", MessageLevel.ODBC);
cfg.AddResource(@"KalSharp.Account.hbm.xml", System.Reflection.Assembly.GetExecutingAssembly());
//building config
KalAuth = cfg.BuildSessionFactory();
ServerConsole.WriteLine("Connected to KalAuth", MessageLevel.ODBC);
//create config
ServerConsole.WriteLine("Connecting to KalDB...", MessageLevel.ODBC);
Configuration cfg2 = new Configuration().Configure("kaldb.cfg.xml");
//load resources
ServerConsole.WriteLine("Loading resources", MessageLevel.ODBC);
cfg2.AddResource(@"KalSharp.Player.hbm.xml", System.Reflection.Assembly.GetExecutingAssembly());
cfg2.AddResource(@"KalSharp.PlayerDeleted.hbm.xml", System.Reflection.Assembly.GetExecutingAssembly());
cfg2.AddResource(@"KalSharp.Worlds.Items.Item.hbm.xml", System.Reflection.Assembly.GetExecutingAssembly());
//building config
KalDB = cfg2.BuildSessionFactory();
ServerConsole.WriteLine("Connected to KalDB", MessageLevel.ODBC);
}
示例3: SetUp
public virtual void SetUp()
{
Configuration cfg = new Configuration();
Assembly dm = Assembly.GetAssembly(typeof(Simple));
cfg.AddResource("NHibernate.DomainModel.Simple.hbm.xml", dm);
cfg.AddResource("NHibernate.DomainModel.NHSpecific.SimpleComponent.hbm.xml", dm);
cfg.AddResource("NHibernate.DomainModel.Multi.hbm.xml", dm);
factory = cfg.BuildSessionFactory();
factoryImpl = (ISessionFactoryImplementor) factory;
dialect = factoryImpl.Dialect;
}
示例4: WrongPropertyNameForCamelcaseShouldThrow
public void WrongPropertyNameForCamelcaseShouldThrow()
{
//default-access="field.camelcase" on property
var cfg = new Configuration();
Assert.Throws<MappingException>(() =>
cfg.AddResource(ns + "DogMapping.hbm.xml", Assembly.GetExecutingAssembly()));
}
示例5: SupportTypedefInReturnScalarElements
public void SupportTypedefInReturnScalarElements()
{
var cfg = new Configuration();
Assembly assembly = Assembly.GetExecutingAssembly();
cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1605.Mappings.hbm.xml", assembly);
using (cfg.BuildSessionFactory()) {}
}
示例6: MisspelledPropertyName
public void MisspelledPropertyName()
{
bool excCaught = false;
// add a resource that has a bad mapping
string resource = "NHibernate.Test.MappingExceptions.A.PropertyNotFound.hbm.xml";
Configuration cfg = new Configuration();
try
{
cfg.AddResource( resource, this.GetType().Assembly );
cfg.BuildSessionFactory();
}
catch( MappingException me )
{
//"Problem trying to set property type by reflection"
// "Could not find a getter for property 'Naame' in class 'NHibernate.Test.MappingExceptions.A'"
Assert.IsTrue( me.InnerException is MappingException );
Assert.IsTrue( me.InnerException.InnerException is PropertyNotFoundException );
Exception inner = me.InnerException.InnerException;
Assert.IsTrue( inner.Message.IndexOf( "Naame" ) > 0, "should contain name of missing property 'Naame' in exception" );
Assert.IsTrue( inner.Message.IndexOf( "NHibernate.Test.MappingExceptions.A" ) > 0, "should contain name of class that is missing the property" );
excCaught = true;
}
Assert.IsTrue( excCaught, "Should have caught the MappingException that contains the property not found exception." );
}
示例7: MisspelledPropertyName
public void MisspelledPropertyName()
{
bool excCaught = false;
// add a resource that has a bad mapping
string resource = "NHibernate.Test.MappingExceptions.A.PropertyNotFound.hbm.xml";
Configuration cfg = new Configuration();
try
{
cfg.AddResource(resource, GetType().Assembly);
cfg.BuildSessionFactory();
}
catch (MappingException me)
{
PropertyNotFoundException found = null;
Exception find = me;
while (find != null)
{
found = find as PropertyNotFoundException;
find = find.InnerException;
}
Assert.IsNotNull(found, "The PropertyNotFoundException is not present in the Exception tree.");
Assert.AreEqual("Naame", found.PropertyName, "should contain name of missing property 'Naame' in exception");
Assert.AreEqual(typeof(A), found.TargetType, "should contain name of class that is missing the property");
excCaught = true;
}
Assert.IsTrue(excCaught, "Should have caught the MappingException that contains the property not found exception.");
}
示例8: 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) {}
}
示例9: 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);
}
示例10: 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);
}
示例11: CanLoadMappingWithNotNullIgnore
public void CanLoadMappingWithNotNullIgnore()
{
var cfg = new Configuration();
if (TestConfigurationHelper.hibernateConfigFile != null)
cfg.Configure(TestConfigurationHelper.hibernateConfigFile);
Assert.DoesNotThrow(
() => cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1255.Mappings.hbm.xml", typeof (Customer).Assembly));
}
示例12: ValidateQuickStart
public void ValidateQuickStart()
{
Configuration cfg = new Configuration();
cfg.AddResource( "NHibernate.Examples.ForumQuestions.T1078029.Member.hbm.xml", Assembly.Load("NHibernate.Examples") );
ISessionFactory factory = cfg.BuildSessionFactory();
}
示例13: ClassMissingDefaultCtor
public void ClassMissingDefaultCtor()
{
// add a resource that doesn't exist
string resource = "NHibernate.Test.MappingExceptions.MissingDefCtor.hbm.xml";
Configuration cfg = new Configuration();
cfg.AddResource(resource, this.GetType().Assembly);
Assert.Throws<InstantiationException>(() =>cfg.BuildSessionFactory());
}
示例14: OrderingAddResources
public void OrderingAddResources()
{
Configuration cfg = new Configuration();
foreach (string res in Resources)
{
cfg.AddResource(res, MyAssembly);
}
cfg.BuildSessionFactory().Close();
}
示例15: 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);
}