C# NHibernate无效强制转换-使用查询时属性类型不匹配

C# NHibernate无效强制转换-使用查询时属性类型不匹配,c#,nhibernate,orm,nhibernate-mapping,C#,Nhibernate,Orm,Nhibernate Mapping,在阅读了几个小时的类似问题后,我仍然无法找到我所面临的问题。查询中出现异常,如下所示: Configuration config = new Configuration(); config.AddAssembly(typeof(TestCase).Assembly); ISessionFactory sessionFactory = config.BuildSessionFactory(); var session = sessionFactory.OpenSes

在阅读了几个小时的类似问题后,我仍然无法找到我所面临的问题。查询中出现异常,如下所示:

    Configuration config = new Configuration();
    config.AddAssembly(typeof(TestCase).Assembly);
    ISessionFactory sessionFactory = config.BuildSessionFactory();
    var session = sessionFactory.OpenSession();
    ICriteria targetObjects = session.CreateCriteria(typeof(TestCase));
    IList<TestCase> itemList = targetObjects.List<TestCase>(); //Exception raised here
    public virtual Guid Id               { get; set; }
    public virtual ushort Priority       { get; set; }
    public virtual string Description    { get; set; }
    public virtual IList<string> Project { get; set; }
    public virtual string Name           { get; set; }
    public virtual DateTime? Created     { get; set; }
    public virtual DateTime? Updated     { get; set; }
我已经能够使用这个映射将值加载到表中,但是我无法使用任何类型的查询而不找到这个错误。我看了看自己,似乎找不到原因

我的尝试:
-不同的查询
-更改日期时间?到DateTime(将此作为可能的解决方案阅读)
-对发生异常的行的结构进行了修改


在过去的几天里,我在这个和类似的基本问题上坚持了好几个小时,如果有任何帮助,我将不胜感激。

找到了一个解决方案,我不知道为什么我以前没有考虑它


通过从.hbm.xml中删除类型,它可以让查询不受阻碍地进行。经过更多的测试后,我得出结论,Priority列不喜欢成为int或uint。我假设MySQL存储整数的方式与C#的方式相比存在问题,很可能是因为我在数据库端将它们标记为未签名。作为修复,我只是从XML中删除了该类型。

TestProject.TestCase
实际名称,还是因为这个问题而重命名了它们?我问这个问题是因为我觉得这个问题中没有什么东西是对的。您有
namespace=“TestProject.TestCase”
,以及
class name=“TestProject.TestCase”
,还有一个错误,它说明了有关名为
TestProject.TestCase
的属性的某些内容。因此,所有三个名称空间、类和属性的名称都完全相同。要么这是你的问题,要么你陈述问题的方式有错误;根据我在安装过程中收集的其他信息,这似乎是正确的做法。不过,我会看看这是否能解决问题。谢谢这似乎没有解决任何问题,但我确实清理了XML,它仍然可以将数据插入表中。我在主要帖子中相应地更新了XML。当我再次查看代码时,我在其他地方发现了一些差异,我对这些差异做了一些其他测试,但它们也没有完成任何工作。我会继续努力的。再次感谢您的投入!
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                       assembly="TestProject"
                       namespace="TestProject">
      <class name="TestCase"
             table="test_table"
             lazy="true">
        <id name="Id" column="ID" type="Guid">
          <generator class="assigned" />
        </id>
        <property name="Priority" column="Priority"
                  type="int" />
        <property name="Description" column="Description"
                  type="string" />
        <property name="Name" column="Name"
                  type="string" />
        <property name="Created" column="Created"
                  type="DateTime" />
        <property name="Updated" column="Updated"
                  type="DateTime" />
        <list table="ProjTable" name="Project">
          <key column="TestID" />
          <list-index column="ProjIndex" />
          <element column="ProjCol" />
        </list>
     </class>
    </nhibernate-mapping>
    NHibernate: SELECT this_.ID as ID0_0_, this_.Priority as Priority0_0_,
    this_.Description as Descript4_0_0_, this_.Test_Name as Test5_0_0_, 
    this_.Created as Created0_0_, this_.Updated as Updated0_0_ FROM test_table this_