0

我正在创建一个自定义员工模块。一名员工最多可以拥有三个地址。我正在尝试关注这篇文章 - http://docs.orchardproject.net/Documentation/Creating-1-n-and-nn-relations

这就是我在 Migrations.cs 中的内容。

 SchemaBuilder.CreateTable("EmployeeRecord",
        table => table
            .ContentPartRecord()
            .Column<int>("EmployeeId")
            ...
            .Column<int>("AddressRecord_Id")
        );


SchemaBuilder.CreateTable("AddressRecord",
    table => table
        .Column<int>("Id", column => column.PrimaryKey().Identity())
        ...
    );

这是模型。

public class EmployeeRecord : ContentPartRecord {
    public virtual int EmployeeId { get; set; }
    ...
    public virtual AddressRecord AddressRecord { get; set; }
}

public class AddressRecord {
    public virtual int Id { get; set; }
    ...
}

提交 create-new-employee 表单时,我得到具有多个地址的数据。我可以创建一个新的员工内容类型。但我不确定如何创建三个地址并将其分配给该员工。有什么帮助吗?

谢谢。

4

1 回答 1

2

您的模型的基础知识错了:如果员工有地址,那么地址应该指向员工,而不是员工指向地址。除非你真的永远不会有超过三个,在这种情况下你可以拥有 Address1、Address2 和 Address3 属性。无论如何,我建议在继续之前阅读更多关于关系数据库中关系表示的内容。

于 2012-04-26T01:28:27.523 回答