NHibernate mapping: entity property corresponding to presence of record in another table
I'm pretty sure what sort of things can be done with NHibernate but I wanted to check with the community on this one.
If I have an entity Foo:
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
public bool HasRegistered开发者_运维技巧 { get; set; }
}
I would like the property HasRegistered
to be true if there is a corresponding record in the Actions
table (i.e. has the Foo's Id
as a foreign key and a particular code 'BLAH' in another field), and to be false if there is not.
So, for example, HasRegistered
would be true if there is an Action
record with the following fields:
FooId
(equal to the Foo'sId
)Code
(equal to the value 'BLAH')
Is such mapping possible?
From my knowledge of NHibernate, this is not possible with a "transparent" mapping feature, like property or as you can do with bags os sets and so on.. The simplest way to that is using a formula over that property and make that property "un-mutable" so the property does'm involve in insert/update scenarios. hope this helps.
so this could be an example:
<property
name="HasRegistered"
formula="sql formula to evaluate"
insert="false" update="false"/>
as source of more info about nhibernate mapping features about (property in this case) is the following: NHibernate mapping: property
精彩评论