我正在尝试通过PersistenceSpecification中的CheckList方法测试私有列表。 但我还没到那里。有人可以帮忙吗?
实体:
public class Item: Entity<int>
{
//values in list are used in later (internal) calculations
private readonly IList<PurchaseInfo> _purchaseInfo = new List<PurchaseInfo>();
public virtual string SupplierCode {get; set;}
}
地图:
public class ItemMap: ClassMap<Item>
{
public ItemMap()
{
Table("ITEM");
Id(u => u.Id).Column("ITEMNR").GeneratedBy.Assigned();
Map(u => I.SupplierCode).Column("SUPPLIERNR");
HasMany<PurchaseInfo>(Reveal.Member<Item>("_purchaseInfo"))
.KeyColumns.Add("ITEMNR")
.KeyColumns.Add("SUPPLIERNR").PropertyRef("SupplierCode");
}
}
测试(这是我目前正在尝试的方式)
[Test]
public void CanMapItem()
{
new PersistenceSpecification<Item>(Session)
.CheckProperty(a => a.Id, 1234)
.CheckProperty(a => a.SupplierCode, "S01")
.CheckList<Item, PurchaseInfo>(Reveal.Member<Item>("_purchaseInfo"), new List<PurchaseInfo>
{
new PurchaseInfo()
{
ItemNr = 1234,
SupplierCode = "S01"
},
new PurchaseInfo()
{
ItemNr = 1234,
SupplierCode = "S02"
}
})
.VerifyTheMappings();
}
编译器抱怨CheckList期望作为第一个参数
System.Linq.Expressions.Expression<System.Func<Item, System.Collections.Generic.IEnumerable<PurchaseInfo>>
而Reveal.Member返回
System.Linq.Expressions.Expression<System.Func<Item, object>>
答案 0 :(得分:1)
Reveal.Member
有2个重载,一个是常见的,一个是特殊的。使用特殊的:
.CheckList<Item, PurchaseInfo>(Reveal.Member<Item, IEnumerable<PurchaseInfo>>("_purchaseInfo"),