0

I hope you can help with my scenario. I have two db tables. The first one is called status and does not change. It contains two columns, one for the ID and another called status which contains the values "Queued", "In Process" "Treated"

The second table is called Activity and uses a FK to constrain the status of an activity

Using fluent Nhibernate, if i want to insert a new row into Table.Activity do i need to reference the entity(table) 'status' in the entity Activity and associated mapping, for example:

public virtual Status Status { get; set; }  // Activity Entity Class

References(a => a.Status);  // Activity Mapping Class

And if i did that then how would I save the new session

session.Save(new Activity
{
    Name = "Activity A1DD", 
    Status = new Staus { ID = 1 } // But can't do that cause its expecting an object
}

The alternative I can see is just to represent the FK as an integer and create an enum class that represents this table and don't worry about the relationship using fluent?

Thanks

GB

beaumondo
  • 4,862
  • 7
  • 29
  • 42

1 Answers1

0

either use the existing status

session.Save(new Activity
{
    Name = "Activity A1DD", 
    Status = session.Get<Status>(1)
});

tell it to use the existing status in the database with given id (without loading it)

session.Save(new Activity
{
    Name = "Activity A1DD", 
    Status = session.Load<Status>(1)
});

ditch the whole Status table and use an Enum instead (enough when the status has no properties/behavior)

session.Save(new Activity
{
    Name = "Activity A1DD", 
    Status = Status.InProcess
});
Firo
  • 30,626
  • 4
  • 55
  • 94