Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="false">
<class name="Services.SharedNhibernate.PlantModel, SharedNHibernateModels"
optimistic-lock="version"
table="plants">
<id name="id" column="id" type="Byte" >
<generator class="identity" />
</id>
<version name="optimisticLock" column="optimistic_lock" type="Int16" />
<property name="name" column="name" type="String" length="50"/>
<property name="UTCOffset" column="utc_offset" type="Int16" />
<property name="createdOn" column="created_on" type="DateTime" />
<property name="lastEditedOn" column="last_edited_on" type="DateTime" />
<property name="lastEditedBy" column="last_edited_by" type="Int32" />
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<!-- This entity is read only -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="false">
<class name="Services.User.PlantModel, User"
mutable="false"
table="Plants">
<id name="id" column="id" type="Byte" >
<generator class="identity" />
</id>
<property name="name" column="name" type="String" length="50"/>
</class>
</hibernate-mapping>
Code:
CREATE TABLE [dbo].[Plants](
[id] [tinyint] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[utc_offset] [smallint] NOT NULL,
[created_by] [int] NOT NULL,
[created_on] [datetime] NOT NULL,
[last_edited_by] [int] NOT NULL,
[last_edited_on] [datetime] NOT NULL,
[optimistic_lock] [smallint] NOT NULL,
CONSTRAINT [PK_Plants] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Both configurations map to the same table, but one of them is read-only. I'm changing the way I'm handling factories so I only create it once, which means I need to include all of the configurations. There are a few other approaches I'm going to try if I can't do this with NHibernate (but I'm hoping I can).
Also, I've been moving all of my NHibernate models into a separate DLL specifically for them rather than littering them throughout the services. This is my first project with NHibernate and I've come to the conclusion that it's a better way to operate in general. At least I think so, I'm interested in your opinion on the matter.