我有我的数据库中有两个2表MVC 3剃须刀显示父/子表作为一个表
Table: Foo Table: Bar
----------------- ---------------------
|FooID | Int| |BarID | Int |
|Number | Int| |FooID | Int |
----------------- |Name | String |
|Value | Int |
---------------------
With data with data
|FooID | Number | |BarID |FoodID |Name |Value |
|1 | 1 | |1 |1 |apple |100 |
|2 | 2 | |2 |1 |orange |110 |
|3 |2 |apple |200 |
|4 |2 |orange |40 |
以上是相关车型
class Foo
{
public int FooID { get; set; }
public int Number { get; set;}
public virtual ICollection<Bar> Bars { get; set; }
}
class Bar
{
public int BarID { get; set; }
public int FooID { get; set; }
public string Name { get; set;}
public int Value { get; set;}
}
我可以伊斯利在这样一个表中显示此通过在其输出
视图<table>
@foreach(var f in Model)
{
<tr>
foreach(var b in f.Bar)
{
<td>@f.Number</td>
<td>@b.Name</td>
<td>@b.Value</td>
}
</tr>
}
</table>
做follwing格式
-------------------
|1 |apple |100|
-------------------
|1 |orange |110|
-------------------
|2 |apple |200|
-------------------
|2 |orange | 40|
-------------------
我真的会看到输出结果如下。
-------------------------
| | 1 | 2 |
-------------------------
|apple |100 |200 |
-------------------------
|orange |200 | 40 |
-------------------------
有人能指点我在正确的方向?
你肯定Foo.Number将始终从1开始,sequencialy增长? – Mohayemin 2012-07-20 23:14:10
感谢您的回复。是的,我确信它将从1开始并逐步增长......但是这很重要吗?如果Foo.Number是一个字符串而不是Int?任何建议帮助。再次感谢! – 2012-07-20 23:36:20
噢,我想我知道你可能在...... Foo.Number将重置为1并在我的应用程序中再次备份。我试图通过删除多余的字段来简化我的问题。 – 2012-07-20 23:39:20