I'm using Fluent NHibernate (v. 1.3) and I have two entites:
public class MyObject
{
public virtual int Id { get; protected set; }
public virtual string Tag { get; set; }
public virtual List ListValue { get; set; }
}
public class List
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
}
The mapping looks like this:
public MyObjectMap()
{
Table("my_table");
Id(x => x.Id).Column("dtl_id").GeneratedBy.Native();
Map(x => x.Tag).Column("mfl_tag").Not.Nullable();
References<List>(x => x.ListValue).Column("lst_id").Nullable();
}
public ListMap()
{
Id(x => x.Id).Column("lst_id").GeneratedBy.Native();
Map(x => x.Name).Column("lst_name").Nullable().Length(50);
}
Now I would like to set the "lst_id" value on MyObject (that is ListValue.Id).
Usually I would just set the ListValue property to an instance of a List object, but in a particular case I just have an Id.
I could use the Id to get the List object from the database but that seems unnecessary since I don't want to do anything with the list object itself, I just want to set the lst_id value and save the object.
Another option would be to change the setter property of Id in List to public instead of protected. Then I could create a new List instance, set the Id to whatever I want and assign it to MyObject.ListValue. This would also work, but it feels wrong since Id is generated by the database and having the setter as protected shows that clearly.
Is there a third option?