public class WorldEntity
{
public WorldEntity()
{
Scenes = new List<SceneEntity>();
}
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Picture { get; set; }
public virtual IList<SceneEntity> Scenes { get; set; }
}
public class WorldMap : ClassMap<WorldEntity>
{
public WorldMap()
{
Table("Worlds");
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Name);
Map(x => x.Picture);
HasMany(x => x.Scenes).KeyColumn("Id");
}
}
public class SceneEntity
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
public virtual string Image { get; set; }
//public virtual int WorldId { get; set; }
public virtual WorldEntity World { get; set; }
public virtual short NoExits { get; set; }
public virtual string AnimatedIntroPath { get; set; }
}
public class SceneMap: ClassMap<SceneEntity>
{
public SceneMap()
{
Table("Scenes");
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Name);
Map(x => x.Image);
Map(x => x.NoExits);
Map(x => x.AnimatedIntroPath);
//Map(x => x.WorldId).Not.Nullable();
References(wrd => wrd.World, "WorldId");
}
}
[Test]
new PersistenceSpecification<SceneEntity>(Session)
.CheckProperty(x => x.Name, "Scene Name")
.CheckProperty(x => x.Image, "path to image")
//.CheckProperty(x=>x.WorldId,aa.Id)
.CheckReference(x => x.World,aa )
.VerifyTheMappings();
运行测试后,我收到此错误:
System.ApplicationException:对于属性 'World' 需要相同的元素,但得到了不同类型的 'TwitQuestNet.DataDefinitions.OrmConfig.Entities.WorldEntity' 元素。提示:覆盖类型上的 ToString() 以找出差异。在 FluentNHibernate.Testing.Values.Property 2.CheckValue(Object target)
at System.Collections.Generic.List
1.ForEach(Action 1 action)
at FluentNHibernate.Testing.PersistenceSpecification
1.VerifyTheMappings(T first) at TwitQuestNet.Test.EntityMapTests.SceneTest.scene_map_succsess() 在 SceneTest.cs:第 23 行
我在这里做错了什么?因为我被困了将近一天:(