0

Can you suggest a valid mapping for the following scenario. Two tables:

CREATE TABLE "ORDER"
  (
    "ID"      NUMBER(20,0) NOT NULL ENABLE,
    "STATUS_ID"  NVARCHAR2(10,0)
  );

CREATE TABLE "STATUS"
  (
    "ID"      NVARCHAR2(10,0) NOT NULL ENABLE,
    "DESCRIPTION"  NVARCHAR2(250,0)
  );

The respective classes are:

public class Order
{
    public virtual Id { get; set; }
    public virtual Status { get; set; }
}

public class Status
{
    public virtual Id { get; set; }
    public virtual Description { get; set; }
}

Status table is static table of value object for the property Proposal.Status and should never be manipulated by code. I want the Order to always be loaded with Status description and code, i.e. Eager Load Proposal.Status.

I've read this Ayende's blog post but there is no exactly the same scenario, albeit I believe it's quite common.

Edit: note I'm trying to do this as Component Map.

Community
  • 1
  • 1
Ruslan
  • 9,927
  • 15
  • 55
  • 89

1 Answers1

2

You are trying to map a regular entity with identity as a component (value object). From Ayende's post:

In DDD you have the notion of entities and value objects. The latter are immutable and have no identity. In NHibernate they are mapped as Component and its fields are embedded in the same table as the containing entity.

Component mapping should be used when you are mapping a value type to the same table as the parent entity. You can find more information about NHibernate types in documentation.

Try instead to do it using References mapping, although you might be tempted to use HasOne.

Community
  • 1
  • 1
Miroslav Popovic
  • 12,100
  • 2
  • 35
  • 47
  • Funny enough, I've started with `HasOne` before I realised it wasn't appropriate. I did think that Status is a Value Object, but yes it will have a natural Id field (`StatusCode`), so I guess it isn't. `References` does the job allright. – Ruslan Oct 03 '12 at 11:08