ユーザーが製品のカスタムフィールドを持つことを可能にするCustomProductPropertyモデルがあり、その中にユーザー定義のデータタイプを処理するデータベースにリンクさ れたCustomDataTypeモデルが含まれています。
[Table("Product")]
public class Product
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ProductID { get; set; }
public int ProductTypeID { get; set; }
[Display(Name = "Product Name")]
public string ProductName { get; set; }
[ForeignKey("ProductTypeID")]
[Display(Name = "Product Type")]
public virtual ProductType ProductType { get; set; }
public virtual ICollection<CustomProductProperty> CustomProperties { get; set; }
}
[Table("CustomProductProperty")]
public class CustomProductProperty
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CustomPropertyID { get; set; }
public int CustomDataTypeID { get; set; }
[ForeignKey("CustomDataTypeID")]
public virtual CustomDataType DataType { get; set; }
public int ProductID { get; set; }
[ForeignKey("ProductID")]
public virtual Product Product { get; set; }
public string PropertyValue { get; set; }
}
[Table("CustomDataType")]
public class CustomDataType
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CustomTypeID { get; set; }
public string PropertyName { get; set; }
public CustomDataTypes DataType { get; set; }
public int ModuleID { get; set; }
[ForeignKey("ModuleID")]
public Module Module { get; set; }
}
これをビューに表示しようとすると、 CustomProductPropertyのICollection<>を処理するための表示テンプレートを作成しました 。何らかの理由で、空ですが、正しいデータが返されます。空である理由を知っている人はいますか?DataType.PropertyName
PropertyValue
PropertyName
@model IEnumerable<InventoryManager.Models.CustomProductProperty>
@{
Layout = null;
}
@foreach (var item in Model)
{
<tr>
<th>@Html.DisplayFor(model => item.DataType.PropertyName)</th>
<td>@Html.DisplayFor(model => item.PropertyValue)</td>
</tr>
}