我的数据库中有两个表,其中包含超类和子类的数据。但是,在我的应用程序中,我有一个介于两者之间的中间类,它从底部子类加载其数据......
abstract public class TierSettings
{
public Guid id { get; set; }
public string SomeTierSetting { get; set; }
}
abstract public class PricingStrategy : TierSettings
{
public string StrategySetting1 { get; set; }
public string StrategySetting2 { get; set; }
}
public class FirstPricingStrategy : PricingStrategy
{
public PricingStrategyType Strategy { get { return PricingStrategyType.Strategy1; } }
public Decimal Value { get; set; }
}
public class SecondPricingStrategy : PricingStrategy
{
public PricingStrategyType Strategy { get { return PricingStrategyType.Strategy2; } }
public Decimal Value { get; set; }
}
在我的数据库中,我只有 2 个表:
TierSettings(
Id Guid Primary Key,
SomeTierSetting NVarChar(100)
)
PricingStrategies(
Id Guid Primary Key, Foreign Key References Parent(Id),
StrategySetting1 NVarChar(100),
StrategySetting2 NVarChar(100),
StrategyType Int,
Value Float
)
我在映射我的 hbm.xml 文件中的关系时遇到问题。如果我将各个 PricingStrategy 类映射为扩展层,我将无权访问 StrategySetting 属性……但我的 PricingStrategy 类不会直接映射到数据库。
我需要能够查询这样的:
var items = from items in session.Query<TierSettings>() select item;
foreach(var item in items)
{
Console.WriteLine(item.Value);
}
如何相应地构建我的映射文件?