0

我是 NHibernate 的新手(使用最新版本),我在将通用数据加载应用程序中的对象映射到数据库时遇到问题。数据库是第三方的,所以我们不能在那里进行更改。

我们的目标是:

public class GenericObjectValue
{
    public string ObjectId { get; set; }
    public string ObjectTypeId { get; set; }
    public string measurementId { get; set; }
    public DateTime timestamp { get; set; }
    public Double Value { get; set; }
}

我们使用的数据源表:

Table t_data_point
(
    id (PK, int, not null)
    object_id (FK, Varchar(30), not null)
    object_type_id (FK, Varchar(30), not null);
    measurement_id (FK, Varchar(30), not null);
)


Table t_data_point_Value
(
    data_point_id (PK, FK, int, not null)
    timestamp (PK, FK, datetime, not null)
    version (PK, FK, int, not null)
    value (numeric(18,6), not null);
) 

我配置的映射是:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Phoenix.Model"     assembly="Phoenix.Common">
 <class name="MeasValue" table="t_data_point_Value">
  <id column="data_point_id" type="int" />
  <property name="Timestamp" column="timestamp "/>
  <property name="Value" column="value"/>

  <join table="t_data_point">
       <key column="id" />
       <property name="measurementId" column="measurement_id" />
       <property name="ObjectId" column="object_id" />
       <property name="ObjectTypeId" column="object_type" />
  </join>
 </class>
</hibernate-mapping>

不确定我是在做一些愚蠢的事情还是不可能的事情,但是当我为此运行代码时,我得到了正确数量的结果,但结果只是返回的第一个结果的重复,即时间戳和值是相同的。

如果您需要更多信息,请告诉我。

4

1 回答 1

0

当您的 id 映射不正确时,我已经看到了这一点,即映射到不唯一的列。Nhibernate 将重用它在缓存中找到的第一个具有相同 ID 的对象。有一个免费的地图工具可以帮助您指明正确的方向。它不会创建连接,但会创建基本列和 ID http://nmg.codeplex.com

于 2013-02-20T19:32:57.123 回答