几天来,我一直在为这个烂摊子苦苦挣扎,试图找出错误的确切原因。一个字,失败!基本上,我一直在尝试对ClassMap
我写的reference
一个引用另一个reference
的 .
[TestMethod]
public void IssueReturnRegisterMap_Create_Success()
{
var maxDifference = TimeSpan.FromMilliseconds(990);
BookSize sz = new BookSize() { ID = "1", Name = "A" };
Department dpt = new Department() { ID = "1", Name = "Philosophy" };
Author auth = new Author() { ID = "2", FirstName = "Wise", LastName = "Person" };
Publisher pub = new Publisher() { ID = "1", Name = "Pub1", Address = "Address 1" };
Language lang = new Language() { ID = "1", Name = "Lang1" };
Patron ptrn = new Patron()
{
ID = "1",
FirstName = "First",
LastName = "Last",
Age = 82,
Address = "Address1",
Gender = "Male",
Occupation = "Occupation1",
Telephone1 = "01234567890",
Telephone2 = "01234567890"
};
Book book = new Book()
{
ID = "1",
Name = "Book1",
Number = "12",
BookSize = sz,
Department = dpt,
Author = auth,
Commentator = "Another wiseman",
Publisher = pub,
Language = lang,
};
Member member = new Member()
{
ID = "1",
Patron = ptrn,
IsRegistered = true
};
//Edit: Acc. to Firo's suggestion
Database.Session.Save( sz );
Database.Session.Save( dpt );
Database.Session.Save( auth );
Database.Session.Save( lang );
Database.Session.Save( pub );
Database.Session.Save( ptrn );
Database.Session.Save( book ); //@Firo: Throws same exception here! :-(
Database.Session.Save( member );
new PersistenceSpecification<IssueReturnEntry>( Database.Session, new CustomEqualityComparer() )
.CheckProperty( x => x.ID, "1" )
.CheckReference( x=> x.Book, book )
.CheckReference( x => x.Member, member )
.CheckProperty( x => x.IssuedBy, "Librarian" )
.CheckProperty( x => x.IssueDate, DateTime.Now, new DateTimeEqualityComparer( maxDifference ) )
.CheckProperty( x => x.DueDate, DateTime.Now, new DateTimeEqualityComparer( maxDifference ) )
.CheckProperty( x => x.ReturnDate, DateTime.Now, new DateTimeEqualityComparer( maxDifference ) )
.CheckProperty( x => x.ReturnBy, "User" )
.VerifyTheMappings();
}
你可以清楚地看到 myBook
是由references
likeBookSize
等组成的Department
。然后它Book
本身就变成了一个references
forIssueReturnRegister
地图。对于Member
. 它为对象引发“非空属性引用空值或瞬态值错误”异常BookSize
。任何帮助是极大的赞赏。提前致谢。