我想知道如何使用 ADO.net 实体数据模型一步创建父对象及其子集合。
示例: 这是父对象“Video”及其子 VideoData 图
我需要使用视频数据创建视频对象
这是脚手架选项创建的剃刀视图
@model Test.Models.Video
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Video</legend>
<div class="editor-label">
@Html.LabelFor(model => model.AddedDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.AddedDate)
@Html.ValidationMessageFor(model => model.AddedDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Data)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Data)
@Html.ValidationMessageFor(model => model.Data)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.IsYouTube)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.IsYouTube)
@Html.ValidationMessageFor(model => model.IsYouTube)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ImageUrl)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ImageUrl)
@Html.ValidationMessageFor(model => model.ImageUrl)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.IsApproved)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.IsApproved)
@Html.ValidationMessageFor(model => model.IsApproved)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ApprovedBy)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApprovedBy)
@Html.ValidationMessageFor(model => model.ApprovedBy)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.LastModifiedDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.LastModifiedDate)
@Html.ValidationMessageFor(model => model.LastModifiedDate)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
如您所见,razor 视图不包含与相关视频数据实体关联的任何字段。
我的问题是:如何将 videoData 添加到视频创建过程中。
如果它可能有帮助,这里是HttpPost
Create in theVideoController
[HttpPost]
public ActionResult Create(Video video)
{
if (ModelState.IsValid)
{
db.Videos.AddObject(video);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(video);
}
我需要发布的视频对象包含其关联VideoData collection
请指教