嗨,在我的数据库中定义了以下表:
Transactions:
- TransactionID (PK, Identity)
- TypeID (FK)
- Amount
TransactionTypes:
- TypeID (PK, Identity)
- Type
ProductTransactions:
- TransactionID (PK)
- Discount
有两种类型的事务(事件和产品)。产品具有附加折扣字段,因此定义了附加表。
我现在有以下实体:
public class Transaction
{
public virtual int TransactionID { get; private set; }
public virtual TransactionType Type { get; set; }
public virtual decimal Amount { get; set; }
}
public class ProductTransaction : Transaction
{
public virtual decimal Discount { get; set; }
}
public enum TransactionType
{
Event = 1,
Product = 1
}
最后,我的映射如下:
public TransactionMap()
{
Table("Transactions");
Id(x => x.TransactionID);
Map(x => x.Amount);
DiscriminateSubClassesOnColumn("TypeID")
.SubClass<ProductTransaction>(TransactionType.Product, x => x.References(y => y.Type));
}
public ProductTransactionMap()
{
Table("ProductTransactions");
Map(x => x.Discount);
}
我想说以下内容来插入产品交易:
productRepository.Insert(new ProductTransaction { Type = TransactionType.Product, Amount = 100m, Discount = 10m });
但是我的地图有问题。我确信我的问题是围绕distingSubclassesonColumn位的,但是我有点迷失在这里。如果有人能告诉我怎么做,我会非常感激的。谢谢