微风+ NHibernate的许多一对一的关系,避免指定关系的钥匙关系、微风、钥匙、NHibernate

2023-09-05 03:32:40 作者:爱情眠于流年

下面的多对一的映射工作(摘自NorthBreeze):

The following many to one mapping is working (taken from NorthBreeze):

public partial class UserRole
{
    public virtual long ID { get; set; }
    public virtual long UserId { get; set; }
    public virtual long RoleId { get; set; }

    public virtual User User { get; set; }
    public virtual Role Role { get; set; }
}

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Models.NorthwindIB.NH" assembly="Model_NorthwindIB_NH">
  <class name="UserRole" table="`UserRole`" dynamic-update="true" optimistic-lock="dirty">
    <id name="ID" column="`ID`" type="long" unsaved-value="0">
      <generator class="native" />
    </id>
    <many-to-one name="User" column="`UserId`" class="User" />
    <many-to-one name="Role" column="`RoleId`" class="Role" />
    <property name="UserId" type="long" not-null="true" insert="false" update="false" />
    <property name="RoleId" type="long" not-null="true" insert="false" update="false" />
  </class>
</hibernate-mapping>

我怎样才能使这种多到一个工作(不包括在模型中指定的用户名和RoleId属性):

How can I make this kind of many to one working (without UserId and RoleId properties specified in the model):

public partial class UserRole
{
    public virtual long ID { get; set; }

    public virtual User User { get; set; }
    public virtual Role Role { get; set; }
}

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Models.NorthwindIB.NH" assembly="Model_NorthwindIB_NH">
  <class name="UserRole" table="`UserRole`" dynamic-update="true" optimistic-lock="dirty">
    <id name="ID" column="`ID`" type="long" unsaved-value="0">
      <generator class="native" />
    </id>
    <many-to-one name="User" column="`UserId`" class="User" not-null="true" />
    <many-to-one name="Role" column="`RoleId`" class="Role" not-null="true" />
  </class>
</hibernate-mapping>

错误抛出: 无法找到匹配的FK财产Models.NorthwindIB.NH.UserRole.User

Error thrown: Could not find matching fk for property Models.NorthwindIB.NH.UserRole.User

会这样莫名其妙地BreezeJs的未来版本进行处理,或者是​​有现在这样做,而不必指定模型本身这些密钥的方法吗?还是有更多的比我所看到的?

Could this be somehow handled in the future versions of BreezeJs, or is there currently a way of doing it without having to specify these keys in the model itself? Or is there more to it than what i'm seeing?

修改(非官方的解决方案): 感谢您对指导我们在正确的方向。由于这是一些我们想要的照顾,我们做了一些修改,我们基于什么史蒂夫施密特说。

EDIT (unofficial solution): Thank you for guiding us in the right direction. As this was something we wanted taken care of, we made some modifications ourselves based on what Steve Schmitt said.

下面是一个链接的变化,使你可以看到我们是如何解决这个问题,所以它可以帮助到别人。 (请注意,这code只对NHibernate的)

Here's a link to the changes so you can see how we solved this issue, so it can be of help to anybody else. (please note that this code only works for NHibernate)

的https://github.com/maca88/Breeze/commit/7a80c35cf0b20b5cffdef6d2eddeccd1bdeb3735

推荐答案

没有,但我们打算解决这个问题。这个问题,因为你和Rippo了解到,在于FKS需要在客户端上的微风工作。他们还要求的SaveChanges 处理过程中重新连接的实体服务器上。

No, but we're planning to fix that. The problem, as you and Rippo have learned, is that the FKs are required on the client for Breeze to work. They are also required to re-connect the entities on the server during the SaveChanges processing.

我们的想法(尚未未尝试过)是:

Our idea (as yet untried) is to:

创建,他们在现实模型不存在必要的外键的属性的元数据。这些将被标记为合成的以某种方式('$'preFIX,特殊的属性等)。 在JSON序列化过程中,从相关实体或NH代理填充合成的外键。 在JSON反序列化过程(保存时),随身携带实体合成外键信息,因此它可以被用来重新建立关系或者创建NH代理。

不是一件容易的事。我们认识到,这是非常重要的谁拥有现有的N /休眠模式,并且不希望修改他们使用微风开发。

Not a trivial exercise. We realize that it's important for developers who have existing N/Hibernate models, and don't want to modify them to use Breeze.

 
精彩推荐