Hi,
I'm trying to use a custom YesNo (a "OuiNon" since I'm french) and can't figure out how to get it working.
I created a new complex type, inheriting from CharBooleanType (exactly like YesNotType does) named OuiNonType, set it to my property, but instead of being boolean, the property is a OuiNonType (and I don't want to; I wan a bool).
Is there a way to achieve this?
Thanks,
Pascal.
Using a custom type mapping with NHibernate
1. Could you please describe the problems you have encountered when the property type in the conceptual part is OuiNonType (not bool)?
2. As a workaround, you should change this piece of code in the GetPropertyTypeName() method in a standard NHibernate template in the following way:
-->
2. As a workaround, you should change this piece of code in the GetPropertyTypeName() method in a standard NHibernate template in the following way:
Code: Select all
else
propertyDataType = codeProvider.GetNullableType(property.Nullable, property.Type);
Code: Select all
else{
propertyDataType = codeProvider.GetNullableType(false, property.Type);
if (propertyDataType == "OuiNonType")
propertyDataType = property.Nullable ? "bool?" : "bool";
else
propertyDataType = codeProvider.GetNullableType(property.Nullable, property.Type);
}
1. I am not sure I understand what you mean by "conceptual part", but I want a type just like the NHibernate YesNoType, except that true and false are 'O' and 'N' (I recently discovered a similar thing with '0' and '1' but NH will probably be able to map it to a boolean harmlessly).
2. The workaround does not work, because:
- it loses the relation to a column when using a custom complex type.
- it creates an instance in ctor
So basically, I would like to create my own custom types which would be handled exactly as NH native types are.
2. The workaround does not work, because:
- it loses the relation to a column when using a custom complex type.
- it creates an instance in ctor
So basically, I would like to create my own custom types which would be handled exactly as NH native types are.
We do not offer you to change the generated code but change the template for code generation:
1) right click on the NHibernate template in Model Explorer > Copy To Model Folder;
2) double click on the template, replace some standard code (mentioned in my last post), save the modified template, and generate the code.
1) right click on the NHibernate template in Model Explorer > Copy To Model Folder;
2) double click on the template, replace some standard code (mentioned in my last post), save the modified template, and generate the code.
This is a type of your property in the DataModel1.Class1.cs file.picrap wrote:I am not sure I understand what you mean by "conceptual part"
The generation of HBM.XML is predefined in our assembly and cannot be changed.picrap wrote:there is no way to change the HBM.XML Nhibernate temple
As a solution, you can implement your own template (Model Explorer > Templates > Add Template | Copy to Model Folder) either to generate your own HBM.XML or to edit the one which is generated by our provider.