Hi! I got the following error message:
System.IndexOutOfRangeException: Invalid index 9 for this SqlParameterCollection with Count=9..
And I absolutely wonder why oO?!
The database schema and the hbm.xml files were all correctly created with FluentNHibernate. The error ocurrs in the CanCorrectlyMapBookmethod, the PersistenceSpecificationTest runs without an error.
[TestClass]
public class PersistenceSpecificationTests
{
private static ISession _session;
[TestInitialize]
public void PersistenceSpecificationTest()
{
_session = Helper.CreateSessionFactory(false, false).OpenSession();
}
[TestMethod]
public void CanCorrectlyMapBook()
{
new PersistenceSpecification<Book>(_session)
.CheckProperty(p => p.IncludesCDDVD, true)
.CheckProperty(p => p.Isbn, "1232324983sfdsdkfj")
.CheckProperty(p => p.Name, "My Book")
.VerifyTheMappings();
}
}
The number 9 might come from the amount of columns the book has got. At first I thought I have to check all properties, but I tested this with another enity in another project and it worked correctly.
Anyone has an idea?
edit:
Here my domain object + mapping:
public interface IEntity
{
int Id { get; set; }
}
public abstract class LoanedItem : IEntity
{
public virtual int Id { get; set; }
public virtual DateTime DateOfIssue { get; set; }
public virtual bool IsLoaned { get; set; }
public virtual String Name { get; set; }
public virtual Employee LoanedBy { get; set; }
public virtual Release Release { get; set; }
public virtual Publisher Publisher { get; set; }
public virtual bool IncludesCDDVD { get; set; }
}
public class Book : LoanedItem
{
public virtual string Isbn { get; set; }
public virtual int Author { get; set; }
}
public class BookMap : ClassMap<Book>
{
public BookMap()
{
// identity mapping
Id(p => p.Id).Column("BookID");
// column mapping
Map(p => p.Author);
Map(p => p.Isbn);
Map(p => p.IncludesCDDVD);
Map(p => p.IsLoaned);
Map(p => p.Name);
// component mapping
// Publisher
Component(p => p.Publisher, m =>
{
m.Map(x => x.Name);
m.Map(x => x.Homepage);
});
// Release
Component(p => p.Release, m =>
{
m.Map(x => x.ReleaseDate);
m.Map(x => x.ReleaseNumber);
});
// reference/association
References(p => p.LoanedBy).Column("EmployeeID");
}
EDIT:
Ok the problem above could be solved.
BUT how can I check a component? When I check a component with CheckProperty an error occurs ... "expected 'DomainModel.Model.Book' but get 'DomainModel.Model.Book' ... ugh :) well whats wrong there? it is exactly the same domain object. I created a new question