データベースの最初のアプローチと私のアプリケーションでは二つのコントローラ私はSamCutReqMasterの私の見解(親)にSamcutAssignmentMasterの「receivedBy」(子クラス)を取得したい.ButそこかもしれSampCutReqMasterSampCutReqMaster.CS
と隣にありましたpublic partial class SampCutReqMaster { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public SampCutReqMaster() { this.SamCutAssignmentMasters = new HashSet<SamCutAssignmentMaster>(); } public decimal SampCutreqID { get; set; } public Nullable<decimal> BuyerID { get; set; } public Nullable<decimal> PatternRefID { get; set; } public Nullable<decimal> PatternStyleID { get; set; } public Nullable<decimal> SampleTypeID { get; set; } public virtual BuyerMaster BuyerMaster { get; set; } public virtual PatternStyle PatternStyle { get; set; } public virtual PatterRefMaster PatterRefMaster { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<SamCutAssignmentMaster> SamCutAssignmentMasters { get; set; } public virtual SampleType SampleType { get; set; } }
SamCutAssignmentMaster
public class SampCutReqMastersController : Controller
{
private ArtEntities db = new ArtEntities();
// GET: SampCutReqMasters
public ActionResult Index()
{
var sampCutReqMasters = db.SampCutReqMasters.Include(s => s.BuyerMaster).Include(s => s.PatternStyle).Include(s => s.PatterRefMaster).Include(s => s.SampleType).Include(s=>s.SamCutAssignmentMasters);
var sampCutReqMasterssort = sampCutReqMasters.ToList().OrderByDescending(a => a.AddedDate);
return View(sampCutReqMasterssort.ToList());
}
}
のインデックスビューとコントローラを作成していた
public partial class SamCutAssignmentMaster
{
public decimal CutAssignID { get; set; }
public decimal SampCutreqID { get; set; }
public System.DateTime ReceivedDate { get; set; }
public string ReceivedBy { get; set; }
public Nullable<decimal> PatternMasterID { get; set; }
public virtual PatternMaster PatternMaster { get; set; }
public virtual SampCutReqMaster SampCutReqMaster { get; set; }
}
SamCutReqMaster(FKがSamCutReqIDある)インデックスビューで
私は
@model IEnumerable<WebArtSampler.Models.SampCutReqMaster>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.ReqNum)
</th>
<th>
@Html.DisplayNameFor(model => model.Fabric)
</th>
<th>
@Html.DisplayNameFor(model => model.SampleRequiredDate)
</th>
<th>
@Html.DisplayNameFor(model => model.AddedDate)
</th>
<th>
@Html.DisplayNameFor(model => model.AddedBy)
</th>
<th>
@Html.DisplayNameFor(model => model.BuyerMaster.BuyerName)
</th>
<th>
@Html.DisplayNameFor(model => model.PatternStyle.StyleName)
</th>
<th>
@Html.DisplayNameFor(model => model.PatterRefMaster.PatterRefNum)
</th>
<th>
@Html.DisplayNameFor(model => model.SampleType.SampleType1)
</th>
<th>
@Html.DisplayNameFor(model => model.SizeDetail)
</th>
<th>
@Html.DisplayNameFor(model => model.Qty)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ReqNum)
</td>
<td>
@Html.DisplayFor(modelItem => item.Fabric)
</td>
<td>
@Html.DisplayFor(modelItem => item.SampleRequiredDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.AddedDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.AddedBy)
</td>
<td>
@Html.DisplayFor(modelItem => item.BuyerMaster.BuyerName)
</td>
<td>
@Html.DisplayFor(modelItem => item.PatternStyle.StyleName)
</td>
<td>
@Html.DisplayFor(modelItem => item.PatterRefMaster.PatterRefNum)
</td>
<td>
@Html.DisplayFor(modelItem => item.SampleType.SampleType1)
</td>
<td>
@Html.DisplayFor(modelItem => item.SizeDetail)
</td>
<td>
@Html.DisplayFor(modelItem => item.Qty)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.SampCutreqID }) |
@Html.ActionLink("Details", "Details", new { id=item.SampCutreqID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.SampCutreqID })
</td>
</tr>
}
</table>
SamcutAssignmentMaster.receivedByにアクセスする必要があります下にrelavant SamcutAssignmentMasterにはデータもありません
実際の作業コードを表示してください。これは決してコンパイルされません –
部分クラスは何ですか?私は知っているが、私はほとんどすべての仮想クラスのプロパティの値を取得することができます。それは、継承とはあまり関係がありません。 – Mardoxx
@Mardoxx私は知っています。表示されるitem.PatterRefMaster.PatterRefNumのようなものです。 IcollectionにあるSamCutAssignmentMastersのプロパティにアクセスすることはできません。public ICollection SamCutAssignmentMasters {get;セット; } –