我是 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>
不确定我是在做一些愚蠢的事情还是不可能的事情,但是当我为此运行代码时,我得到了正确数量的结果,但结果只是返回的第一个结果的重复,即时间戳和值是相同的。
如果您需要更多信息,请告诉我。