c# - How can I insert a table row with a FK referencing an enum equivalent db table in Fluent Nhibernate -
i hope can scenario. have 2 db tables. first 1 called status , not change. contains 2 columns, 1 id , called status contains values "queued", "in process" "treated"
the second table called activity , uses fk constrain status of activity
using fluent nhibernate, if want insert new row table.activity need reference entity(table) 'status' in entity activity , associated mapping, example:
public virtual status status { get; set; } // activity entity class references(a => a.status); // activity mapping class
and if did how save new session
session.save(new activity { name = "activity a1dd", status = new staus { id = 1 } // can't cause expecting object }
the alternative can see represent fk integer , create enum class represents table , don't worry relationship using fluent?
thanks
gb
either use existing status
session.save(new activity { name = "activity a1dd", status = session.get<status>(1) });
tell use existing status in database given id (without loading it)
session.save(new activity { name = "activity a1dd", status = session.load<status>(1) });
ditch whole status table , use enum instead (enough when status has no properties/behavior)
session.save(new activity { name = "activity a1dd", status = status.inprocess });
Comments
Post a Comment