My goal is to configure NHibernate.Envers by a configuration file. As far as I understod the documentation, it should be easily possible by adding a property entry in the NHibernate Core xml file.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NHibernate.Test">
....
<property name="nhibernate.envers.audit_table_suffix">_history</property>
</session-factory>
</hibernate-configuration>
But this leads to an Exception:
The 'name' attribute is invalid - The value 'nhibernate.envers.audit_table_suffix' is invalid according to its datatype 'String' - The Enumeration constraint failed.
I do understand the exception, NHibernate core checks for valid content in the name attribute. How can I set a NHibernate.Envers property?
The same property works when I set it by code:
cfg = new Configuration();
cfg.Configure("NHibernate.cfg.xml");
// NHibernate.Envers Configuration
cfg.SetProperty("nhibernate.envers.audit_table_suffix", "_history");
Unfortunately the documentation is wrong. You cannot put this in your NH Core configuration because NH Core will do schema validation on your xml (and is unaware of the envers properties).
I will update Envers docs shortly.
Related
I am trying to use XSD on a XSD schema generated by trang. It is giving me the following error:
>xsd examcard.xsd /nologo /classes
Schema validation warning: The 'http://www.w3.org/2001/XMLSchema-instance:type' attribute is not declared. Line 33, position 12.
[...]
Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.
Error: Error generating classes for schema 'examcard'.
- The attribute type is missing.
If you would like more help, please type "xsd /?".
What does this error means ? How should I include the type type for XSD to work ?
For reference examcard.xsd is:
<?xml version="1.0" encoding="UTF-8"?>
[...]
<xs:import namespace="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="xsi.xsd"/>
where xsi.xsd is:
<?xml version="1.0" encoding="UTF-8"?>
[...]
<xs:attribute name="type" type="xs:NMTOKEN"/>
And current version is:
>xsd /?
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.8.3928.0]
Full code at:
https://github.com/malaterre/ExamCard/blob/master/xsd/examcard.xsd
I have a test project which uses MSTest. And I have a testsettings file and have a properties in that file. as below.
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="local" id="77572268-dd99-4f8c-a660-f5c8c1eec977"
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Execution>
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
<AssemblyResolution>
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
</TestTypeSpecific>
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
<Properties >
<Property name="AAA" value="val1"></Property>
<Property name="BBB" value="val2"></Property>
</Properties>
</TestSettings>
But how can I access these properties in testsettings file values by name in runtime. How can I do that?
This is what currently I'am trying..
[ClassInitialize]
public static void TestClassInitialize(TestContext context)
{
var sad = context.Properties["AAA"].ToString();
}
And it gives following exception
An exception of type 'System.NullReferenceException' occurred in
TestAutomation.dll but was not handled in user code
Additional information: Object reference not set to an instance of an
object.
And this is not about the System.NullReferenceException and this is about how to access a property in a Test settings file in runtime. So this question is not a duplicate.
I suspect you have not properly configured your .runsettings file.
Follow this link .runsettings file configuration and configure the "SettingsFile" section properly.
Alternatively you can also try "TestRunParameters" section to get this working.
The way you are accessing the properties is not correct. You need to use runsettings file instead.
You were close but you dont need the ending tag of the property tag, here is an example:
<Properties>
<Property name="test" value="testValue"/>
</Properties>
Once that is done you can use the same code to access the data:
context.Properties["AAA"].ToString()
I am having an issue with NHibernate not deleting rows from the database. Nhibernate is saving and updating to the same database without issue.
After running SQL profiler it appears that there is no delete SQL being sent to the database - which makes me think it's a configuration issue but nothing is standing out to me...
Config
Nhibernate version : 3.3.1.4000
FluentNHibernate Version : 1.3.0.733
SQL Server Version : 2008R2
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string_name">IntermediateDatabase</property>
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="show_sql">true</property>
<property name="connection.release_mode">auto</property>
<property name="adonet.batch_size">500</property>
<!-- Mapping assemblies -->
<!-- Can't map it for Fluent NHibernate here; instead, load the mapping assembly in Global.asax.cs.
If you're still using HBMs, you can use the mapping here or pass the assembly via Global.asax.cs
as well, just like you can do with the Fluent NHibernate assembly(s). -->
</session-factory>
</hibernate-configuration>
Thanks
Based on the information from your comment... It seems that your working method is like:
UPDATE
public T SaveOrUpdate(T entity)
{
using (Session)
{
using (TransactionScope scope = new TransactionScope())
{
Session.SaveOrUpdate(entity); scope.Complete();
}
return entity;
}
}
And this is absolutely correct... because your session FlushMode would most likely be:
session.FlushMode = FlushMode.Commit;
Pleae see more details here: Nhibernate Flush works commit doesn't
DELETE
But the poor sister Delete() is not fully supported as mighty Update()
public void Delete(T entity)
{
using (Session)
{
this.Session.Delete(entity);
}
}
So, while even for Delete() the session FlushMode is still hooked on a transaction commit ... there is no transaction. And that's for sure (well most likely) the real reason (as suspected)
Summary, treat both, Update and Delete as the twins... and give them the same care - i.e. transaction
If the deleted object is a part of collection of another object then in the mapping give .Cascade.AllDeleteOrphan() and just remove the item from the collection, then nhibernate will send the delete statement to DB.
I have custom System.Configuration.ConfigurationSection derived class which represents configuration section in my app.config file. I also have xsd schema document for that XML document. Configuration file has the following (simplified) structure:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="sectionOne" type="/*...*/" />
<section name="sectionTwo" type="/*...*/" />
<section name="sectionThree" type="/*...*/" />
</configSections>
<sectionOne xmlns="http://tempuri.org/MySchema.xsd">
<Container>
/*...*/
</Container>
</sectionOne >
<sectionTwo xmlns="http://tempuri.org/MySchema.xsd">
<Container>
/*...*/
</Container>
</sectionTwo >
<sectionThree xmlns="http://tempuri.org/MySchema.xsd">
<Container>
/*...*/
</Container>
</sectionThree >
</configuration>
As we can see, I have a several sections of that type, for various purposes, and I retrieve configuration data using ConfigurationManager class:
ConfigurationManager.GetSection(sectionName);
Because section name is not constant string value, xsd schema validate only elements that are children of the root element (starting from Container tag). Therefore in VS2012, in Error list toolbar, I get a following messages:
Could not find schema information for the element 'http://tempuri.org/MySchema.xsd:SectionOne'.
Could not find schema information for the element 'http://tempuri.org/MySchema.xsd:SectionTwo'.
Could not find schema information for the element 'http://tempuri.org/MySchema.xsd:SectionThree'.
How to fix that validation mechanism.
There is no solution that does not involve changing a XSD: it is not possible to write a schema matching elements with arbitrary names. All the possible valid element names must be specified explicitly, so to validate correctly the names of the section elements must be added either to the http://tempuri.org/MySchema.xsd schema or to DotNetConfig.xsd.
I'm creating a Custom tag in my web.config. I first wrote the following entry under the configSections section.
<section name="castle"
type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,
Castle.Windsor" />
But, when I try to create a castle node inside the configuration node as below
<castle>
<components>
</components>
</castle>
I get the following error message:"*Could not find schema information for the element '**castle'*." "***Could not find schema information for the element '**components'***."
Am I missing something? I can't find why. And, if I run the application anyway, I get the following error "Could not find section 'Castle' in the configuration file associated with this domain."
Ps.// The sample comes from "Pro ASP.NET MVC Framework"/Steven Sanderson/APress ISBN-13 (pbk): 978-1-4302-1007-8" on page 99.
Thank you for the help
============================================================
Since I believe to have done exactly what's said in the book and did not succed, I ask the same question in different terms. How do I add a new node using the above information?
=============================================================================
Thank you. I did what you said and do not have the two warnings. However, I've go a big new warning:
"The element 'configuration' in namespace 'MyWindsorSchema' has invalid child element 'configSections' in namespace 'MyWindsorSchema'. List of possible elements expected: 'include, properties, facilities, components' in namespace 'MyWindsorSchema'."
What you get is not an error that will prevent you from running your application. It is just a warning that Visual Studio emits because it does not know the castle node in a config file. You could use a schema to enable intellisense. Download the Castle Windsor Schema file and take a look at the readme.txt inside. It tells you to put windsor.xsd somewhere on your hard drive and then reference it in the config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns="MyWindsorSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="MyWindsorSchema file://S:\Common\Windsor\windsor.xsd">
<configSections>
<section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
</configSections>
<castle>
<components>
</components>
</castle>
</configuration>