specify the column in the mapping but in the class create a private
attribute with the "default" value.
public class Issue
{
  private virtual int LastModifiedByUserID = 0;

  public virtual string Title { get; set; }
  public virtual string Description { get; set; }
}

in the mapping

<property name="LastModifiedByUserID" column="LastModifiedByUserID"
not-null="true" access="field" />


---
Fernando Zago
Alloc IT Business Solutions


On Sun, Jul 12, 2009 at 5:55 AM, Richard Dingwall <[email protected]>wrote:

>
> Hi there,
>
> I am currently creating a new domain model and NHibernate mappings for
> a legacy database, but am having issues with not-null columns that are
> required for INSERTs, but are not part of the domain model.
>
> E.g.:
>
> <class name="Issue" table="Issue">
>  <id name="Id">
>    <generator class="native"/>
>  </id>
>
>  <property name="Title"/>
>  <property name="Description"/>
>
>  <property column="LastModifiedByUserID" not-null="true" resolve-
> using="???" />
> </class>
>
> In this example, the ID, Title and Description are all good, but I
> don't want to pollute my domain entities with some 'LastModifiedBy'
> property (that is logged separately now).
>
> Unfortunately though, the LastModifiedByUserID column is not null, so
> I must provide a value or I cannot use NH at all. And it is still used
> by the rest of the system, so I would like to put a meaningful value
> in if possible (I have a class that work this out).
>
> I've looked at interceptors, IUserTypes, and hunted high and low in
> this group, but can't seem to find any suitable methods. I could do it
> with a custom IEntityPersister, but this looks like overkill just to
> inject one extra column.
>
> Is there any easy way to achieve this with NHibernate?
>
> --
> Richard Dingwall
> http://richarddingwall.name
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to