[英]Saving a collection of records in Orchard
目前,我有一個具有3個字段(名稱,值1,值2)的零件。 我可以在零件上進行創建/編輯/刪除的所有工作。
我現在想做的是有一個包含3列(名稱,值1,值2)的網格,並且可以有多行(由用戶決定行數)。 除非用戶完成,否則將不會保存(將所有行保存在單個回發中)。
我還沒有弄清楚需要什么,因此可以在回發時保存一些項目。
有關如何執行此操作的任何建議?
謝謝!
通過使您的dbms創建和管理1-to-n關系,您可能會擁有一部分與(Name,Value1,Value2)相對應的記錄的集合。
例如,您將擁有
public class ThisIsYourPart : ContentPart<ThisIsYourPartRecord> {
// You can access the list of your records as
// yourPart.Record.YourRecords
}
public class ThisIsYourPartRecord : ContentPartRecord {
public ThisIsYourPartRecord () {
YourRecords= new List<YourRecordWithValues>();
}
public virtual IList<YourRecordWithValues> YourRecords{ get; set; }
}
public class YourRecordWithValues {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Value1 { get; set; } // use your actual type
public virtual ThisIsYourPartRecord ThisIsYourPartRecord { get; set; }
}
public class YourMigration : DataMigrationImpl {
public int Create() {
SchemaBuilder.CreateTable("YourRecordWithValues ", table => table
.Column<int>("Id", col => col.Identity().PrimaryKey())
.Column<string>("Name", col => col.NotNull().Unlimited())
.Column<string>("Value1", col => col.NotNull().Unlimited())
.Column<int>("ThisIsYourPartRecord_Id"));
SchemaBuilder.CreateTable("ThisIsYourPartRecord", table => table
.ContentPartRecord());
}
}
像這樣的代碼應該做到這一點。
我們在https://github.com/bleroy/Nwazet.Commerce中經常使用這種關系
*編輯:當然,將所有代碼保存在正確的文件和文件夾中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.