Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# nhibernate:一对一映射_C#_.net_Nhibernate_Nhibernate Mapping_Orm - Fatal编程技术网

C# nhibernate:一对一映射

C# nhibernate:一对一映射,c#,.net,nhibernate,nhibernate-mapping,orm,C#,.net,Nhibernate,Nhibernate Mapping,Orm,我有下面的地图。我希望将BasketItem映射到类“Product”。因此,基本上,当我遍历篮子时,我可以得到产品名称 <class name="BasketItem" table="User_Current_Basket"> <id name="Id" type="Int32" column="Id" unsaved-value="0"> <generator class="identity"/> </id> <property name

我有下面的地图。我希望将BasketItem映射到类“Product”。因此,基本上,当我遍历篮子时,我可以得到产品名称

<class name="BasketItem" table="User_Current_Basket">
<id name="Id" type="Int32" column="Id" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="ProductId" column="Item_ID" type="Int32"/>
  <one-to-one   name="Product"
        class="Product"></one-to-one>
</class>
如何指定产品应与BasketItem.ProductId和product.Id匹配

您的
BasketItem
应该在对象级别保存
产品,而不是
ProductId
。映射应为:

<class name="BasketItem" table="User_Current_Basket">
  <id name="Id" type="Int32" column="Id" unsaved-value="0">
    <generator class="identity"/>
  </id>
  <one-to-one name="Product" class="Product"/>
</class>
如何指定产品应与BasketItem.ProductId和product.Id匹配

您的
BasketItem
应该在对象级别保存
产品,而不是
ProductId
。映射应为:

<class name="BasketItem" table="User_Current_Basket">
  <id name="Id" type="Int32" column="Id" unsaved-value="0">
    <generator class="identity"/>
  </id>
  <one-to-one name="Product" class="Product"/>
</class>

谢谢,关于一对一。“BasketItem”如何知道它必须匹配BasketItem.ProductId=product.Id上的所有产品。我在上面添加了一些sql,这可能会clear@frosty嗯,这正是映射所说的,这正是NHibernate的工作(如果不使用NHibernate的默认值,您可能需要在
一对一
关系中添加
属性)。你试过了吗?谢谢,我在一对一上找不到列属性。我已经设置了多对一,它似乎有效,但我认为我现在已经发布了会话。我发布了一个关于这个的新问题。我在另一篇文章中看到了类似的答案,这是我还没有完全理解的——这就是为什么1-1对象关系应该映射为Nhib的M-1。你能给我一个简单的解释为什么这是有意义的,或者给我一个这样做的链接吗?此外,如果您可以编辑您的帖子,以反映多对一映射。干杯谢谢,关于一对一。“BasketItem”如何知道它必须匹配BasketItem.ProductId=product.Id上的所有产品。我在上面添加了一些sql,这可能会clear@frosty嗯,这正是映射所说的,这正是NHibernate的工作(如果不使用NHibernate的默认值,您可能需要在
一对一
关系中添加
属性)。你试过了吗?谢谢,我在一对一上找不到列属性。我已经设置了多对一,它似乎有效,但我认为我现在已经发布了会话。我发布了一个关于这个的新问题。我在另一篇文章中看到了类似的答案,这是我还没有完全理解的——这就是为什么1-1对象关系应该映射为Nhib的M-1。你能给我一个简单的解释为什么这是有意义的,或者给我一个这样做的链接吗?此外,如果您可以编辑您的帖子,以反映多对一映射。干杯
<class name="BasketItem" table="User_Current_Basket">
  <id name="Id" type="Int32" column="Id" unsaved-value="0">
    <generator class="identity"/>
  </id>
  <many-to-one name="Product" class="Product"/>
</class>