I am trying to implement an interface from a another project and persist that to a data base using fluent nhibernate. I have figured out how to persist a single instance of the interface but can not figure out how to do the entire list.
My class definitions are as follows:
public interface IRunnable { int Velocity { get; set; } int GetSpeed(); }
public class Person : IRunnable
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
//public virtual IList<Car> Cars { get; set; }
public Person()
{
//this.Cars = new List<Car>();
}
public virtual int GetSpeed()
{
return -1;
}
public virtual int Velocity { get; set; }
}
public class Person1 : IRunnable
{
public virtual int Id { get; set; }
public virtual int Age { get; set; }
public virtual int Velocity { get; set; }
public virtual int GetSpeed()
{
return 0;
}
}
public class Car
{
public virtual int Id { get; set; }
public virtual IRunnable Runnable { get; set; }
public virtual IList<IRunnable> Runnables { get; set; }
public Car()
{
Runnables = new List<IRunnable>();
}
}
Mapping definitions are
public class Person1Map : ClassMap<Person1>
{
public Person1Map()
{
Id(x => x.Id);
Map(x => x.Age);
Map(x => x.Velocity);
}
}
public class PersonMap : ClassMap<Person>
{
public PersonMap()
{
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Velocity);
//HasMany(x => x.Cars).Cascade.All();
}
}
public class CarMap : ClassMap<Car>
{
public CarMap()
{
Id(x => x.Id);
ReferencesAny<IRunnable>(x => x.Runnable)
.IdentityType<int>()
.EntityTypeColumn("RunnableType")
.EntityIdentifierColumn("RunnableId")
.AddMetaValue<Person>("P")
.AddMetaValue<Person1>("P1")
.Cascade.All();
HasMany(x => x.Runnables)
.KeyColumn("RunnableId")
.Cascade
.All();
}
}
The references Any works great for a single instance of the interface how can I use something like this when I have entire list of the interface?
Thanks!