【发布时间】:2012-01-29 14:17:21
【问题描述】:
我有一个类和所有属性,但一个映射到相应的表列。现在,当 nhibernate 创建类的新实例时,我想将剩下的一个属性设置为某个值。
例如。
--only two columns
CREATE TABLE [dbo].[Person](
[key] [int] NOT NULL,
[Name] [nvarchar](50) NULL)
--..........
public class Entity
{
public int key {get;set;}
public string EntityType {get;set;}
}
public class Person : Entity
{
public string Name {get;set;}
}
and i have maps
Map(Person => Person.key).Not.Nullable();
Map(Person => Person.Name).Not.Nullable();
// i don't want a map for EntityType
这里我想要一个 Person 实例,EntityType 应该始终设置为自定义字符串“Person”。其他属性通常映射到 Person Table 的相应列。
这可能吗?
【问题讨论】:
-
从继承类的构造函数中设置EntityType属性怎么样?或者也许只是 public string EntityType { get { return this.GetType().Name; } }
标签: nhibernate orm mapping subclassing