Here we go…
I have a table (which unfortunately I can’t change) with columns like:
- date
- startTime
- endTime
I have data classes with two fields:
startDateTime = date + startTime
endDateTime = date + endTime
Map(x => x.EndDateTime)
.Columns.Clear()
.Columns.Add("date", "endTime")
.CustomType<MyCustomType>();
Map(x => x.StartDateTime)
.Columns.Clear()
.Columns.Add("date", "startTime")
.CustomType<MyCustomType>();
MyCustomType is a class implementing IUserType interface. This seemed to work, but it works only with reading data from database. While saving or updating NHibernate puts column “date” twice, and query can not be commited.
My question is: is any way to go around this? I want both fields to be not-read-only. (setting one of them as read-only helps, but it’s not a solution which satisfies me).
Ok, i found a solution… it’s not really elegant, but this database is not elegant either:)
So in my BaseController, which handles all stuff like adding, saving, deleting and updating i did some special handling of saving this particular type:
This SaveSpecialType method executes native sql query inserting that messy type into database