Mapping Enums to Database with NHibernate/Castle ActiveRecord?

Write a generic EnumStringType that overrides SqlType, then apply it.

Write a generic EnumStringType that overrides SqlType, then apply it: public class EnumMapper : NType. EnumStringType { public EnumMapper() { } public override NSqlTypes. SqlType SqlType { get { return new NSqlTypes.

SqlType(DbType. Object); } } } apply it: Property(NotNull = true, ColumnType = "MyNamespace1. EnumMapper`1MyNamespace2.

OrderState, MyAssembly2, MyNamespace1") public OrderState State {get;set;}.

Nope, you must override SqlType. Otherwise, the SQL statement it will insert is: INSERT INTO TestTable (State, Id) VALUES ('Preview'::text, '9dea2a34-566a-45ea-84fd-24b86403ef5b'::uuid) – Mike Jun 7 '10 at 10:56 @Mike: ok, it's necessary to override it when you're using a database enum type. I changed my answer accordingly.

– Mauricio Scheffer Jun 7 '10 at 13:22.

Unless I'm missing something, you can just do this: public enum ExampleEnum { Value1, Value2 } ActiveRecord public class ExampleClass { PrimaryKey public int ID { get; set; } Property public ExampleEnum Example { get; set; } } Seems to work perfectly for me.

Yup, that does work perfectly however it will map to a numeric data type in the database. I was attempting to map it to an ENUM type in the database. I eventually got it working, however it was quite tricky.. – Mike Christensen Nov 12 '10 at 4:17.

Thanks, that helps a bit. However, you can't use EnumStringType directly because it will try to cast it to a 'text' datatype and cause a SQL error. That's why you have to override SqlType and make it a DbTYpe.Object.

I did figure out I could do: Property(SqlType = "TestEnum", ColumnType = "DB. PgEnumMapper`1DB. OrderState, WebSite, WebSite") ...but your way is a bit cleaner.. – Mike Jun 7 '10 at 10:54 .

Net doesn't allow this, as attribute property values have to be static constant expressions: "An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type". If ColumnType was of type System. Type it would be accepted though (without the "AssemblyQualifiedName") – Mauricio Scheffer Jun 7 '10 at 12:48.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions