The persistence specification assumes that you want to use a HashedSet because your collection property is of type ICollection.
Unfortunately I don't really understand why it does this. Perhaps someone that has a better idea of how the persistence specification works can shed some light. The problem method is ListValue.SetValue(object). On Tue, Apr 28, 2009 at 9:19 PM, HMS <[email protected]> wrote: > > Hello, > > While working with Fluent NHibernate to map my entities, I ran into > this exception when trying to test my mappings with the > PersistenceSpecification: > > Test method FluentNHibernateBug.Tests.UnitTest1.TestMethod1 threw > exception: System.InvalidCastException: Unable to cast object of type > 'Iesi.Collections.Generic.HashedSet`1[FluentNHibernateBug.Bar]' to > type 'System.Collections.Generic.IList`1[FluentNHibernateBug.Bar]'.. > > I'm using these entities: > > Bar.cs: > > namespace FluentNHibernateBug > { > public class Bar > { > public virtual int Id { get; set; } > > public virtual string Name { get; set; } > } > } > > Foo.cs: > > using System; > using System.Collections.Generic; > using System.Linq; > using System.Text; > > namespace FluentNHibernateBug.Entities > { > public class Foo > { > public Foo() > { > Bars = new List<Bar>(); > } > > public virtual int Id { get; set; } > public virtual ICollection<Bar> Bars { get; set; } > } > } > > Mappings: > > BarMapping.cs: > > using FluentNHibernate.Mapping; > > namespace FluentNHibernateBug.Mappings > { > public class BarMapping : ClassMap<Bar> > { > public BarMapping() > { > Id(bar => bar.Id); > Map(bar => bar.Name); > } > } > } > > FooMapping.cs: > > using FluentNHibernate.Mapping; > using FluentNHibernateBug.Entities; > > namespace FluentNHibernateBug.Mappings > { > public class FooMapping : ClassMap<Foo> > { > public FooMapping() > { > Id(foo => foo.Id); > HasMany(foo => foo.Bars) > .AsBag(); > } > } > } > > And the unit test that fails me: > > using System; > using System.Text; > using System.Collections.Generic; > using System.Linq; > using FluentNHibernate.Cfg; > using FluentNHibernate.Cfg.Db; > using FluentNHibernate.Testing; > using FluentNHibernateBug.Entities; > using Microsoft.VisualStudio.TestTools.UnitTesting; > using NHibernate.Tool.hbm2ddl; > > namespace FluentNHibernateBug.Tests > { > [TestClass] > public class UnitTest1 > { > [TestMethod] > public void TestMethod1() > { > var configuration = Fluently.Configure() > .Database(SQLiteConfiguration.Standard.InMemory()) > .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Foo> > ()) > .BuildConfiguration(); > > var sessionFactory = configuration.BuildSessionFactory(); > > > var session = sessionFactory.OpenSession(); > > new SchemaExport(configuration).Execute(true, true, false, > true, session.Connection, null); > > var specification = new PersistenceSpecification<Foo> > (session); > > var barList = new List<Bar> > { > new Bar{Name = "Bar1"} > }; > > specification > .CheckList(foo => foo.Bars, barList) > .VerifyTheMappings(); > > } > } > } > > Any ideas? > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---
