English 中文(简体)
NHiberate multi一栏绘图收集
原标题:NHibernate multiple column mapping collection
  • 时间:2011-10-10 22:46:54
  •  标签:
  • nhibernate

I have this situation:

我有几张表_1,表_2. 表格_n,它们属于不同数据,但有些领域是共同的,记录_id,表格_id,如果是主要关键。 所有这些表格都有单一分类记录(Id,表格,表格)。

我有另一个表象,有附件_id,记录_id,表格_id(记录_不足,因为记录_id可在表格上重复。 页: 1

我想要将财产贴在班级记录中,以便从 t中获取记录。

你们能否帮助我绘制关于祖国的地图,以便做到这一点?

我感谢任何帮助。

Edit: Forgot to say that a Record on table_X can have multiple attachments :)

最佳回答

您可以通过任何途径实现这一点

abstract class RecordBase
{
    public virtual int Id { get; set; }

    public virtual int FormId { get; set; }
    public virtual ICollection<Attachment> Attachments { get; set; }
}

class RecordA : RecordBase
{ }

class Attachment
{
    public virtual int id { get; set; }

    public virtual RecordBase Record { get; set; }
}

class RecordAMap : ClassMap<RecordA>
{
    public RecordAMap()
    {
        HasMany(x => x.Attachments)
            .Where("Form_Id = 5");
    }
}

class AttachmentMap : ClassMap<Attachment>
{
    public AttachmentMap()
    {
        ReferencesAny(x => x.Record)
            .EntityIdentifierColumn("record_id")
            .EntityTypeColumn("form_id")
            .IdentityType<int>()
            .AddMetaValue<RecordA>("5");
    }
}

最新资料:xml绘图

<bag where="form_id=5">
  <key column="record_id"/>
  <one-to-many class="Attachment1"/>
</bag>

<any name="Item" id-type="System.Int32" meta-type="System.Int32">
  <column name="form_id" />
  <column name="record_id" />
</any>
问题回答

暂无回答




相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签