nhibernate 仅保存必需的属性

发布于 2024-09-16 06:52:37 字数 969 浏览 2 评论 0原文

我正在使用 NHibernate 2.2 进行数据库工作,最近遇到了一个问题。我有一个名为 PrescDrugItem 的类,如下所示,

public class PrescDrugItem
{
    public virtual int ItemNumber { get; set; }

    [DataMember]
    public virtual int AmountIssued { get; set; }

    [DataMember]
    public virtual string TimePeriod { get; set; }
}

下面是我的问题是的映射文件

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly ="DataContractsLib"
               namespace="DataContractsLib.Prescription" >

  <class name="PrescDrugItem">
    <id name="ItemNumber" type="Int32">
       <generator class="native" />
    </id>
    <property name="AmountIssued" type="Int32" />
    <property name="TimePeriod" type="String" length="30" />
  </class>

,现在我需要向类 Item 添加另一个属性(例如 ItemTradeName 等),但我不希望将其保存到数据库中(因为我想要使用这个新属性来临时存储一些数据)。我在映射文件中尝试了 update=false 和 insert=false 但尚未成功。你们能告诉我这是否可行吗?谢谢。

I'm using NHibernate 2.2 for my database work and I've faced an issue recently. I have a class called PrescDrugItem which is shown below

public class PrescDrugItem
{
    public virtual int ItemNumber { get; set; }

    [DataMember]
    public virtual int AmountIssued { get; set; }

    [DataMember]
    public virtual string TimePeriod { get; set; }
}

following is the mapping file

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly ="DataContractsLib"
               namespace="DataContractsLib.Prescription" >

  <class name="PrescDrugItem">
    <id name="ItemNumber" type="Int32">
       <generator class="native" />
    </id>
    <property name="AmountIssued" type="Int32" />
    <property name="TimePeriod" type="String" length="30" />
  </class>

my problem is, now I need to add another property to the class Item (say ItemTradeName etc), but I dont want it to be saved to the database( because I want to use this new property to store some data temporary). I tried update=false and insert=false in the mapping file but no success yet. Could you guys please tell me is this possible thing to do . Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜宝宝 2024-09-23 06:52:37

如果也不想从数据库中获取它,只需将其添加为类的普通属性并且不要映射它。

If it's not to be fetched from the database either, just add it as a normal property of your class and don't map it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文