C# 使用泛型列表,arrayList

C# 使用泛型列表,arrayList,c#,class,model-view-controller,generic-list,C#,Class,Model View Controller,Generic List,我想在函数中填写班级人数。我不知道如何单独添加AmountDetail。 我写的代码中有一个错误。我不能列出班级的人数 public class Amount { public int Id{ get; set; } public AmountDetail AllList { get; set; } public int TotalCount { get; set; } public int Top { get; set; } public int Pag

我想在函数中填写班级人数。我不知道如何单独添加AmountDetail。
我写的代码中有一个错误。我不能列出班级的人数

public class Amount
{
    public int Id{ get; set; }
    public AmountDetail AllList { get; set; }
    public int TotalCount { get; set; }
    public int Top { get; set; }
    public int Page { get; set; }
}

public class AmountDetail
{
    public int Name{ get; set; }
    public int Surname{ get; set; }
}

public IHttpActionResult BildirimTumListeGetir(AmountDetail model)     
{
 List<AmountDetail > amountDetail = new List<AmountDetail >();       
 List<Amount> detailList= new List<Amount>();

    using (var ctx = new ktdbEntities())
    {
      var query = ctx.amountList().ToList();
      var count = query.Count;
      var total = ctx.amountListTotal(model.Id).ToList();
      model.TotalCount = total.Count();
      for(var i = 0; i<count; i++)
      {
         AmountDetail detail= new AmountDetail ();
         detail.Name= query[i].Name;
         detail.Surname= query[i].Surname;

         amountDetail.Add(detail);
      }       
    }
    detailList.Add(model);
    return Ok(detailList);
 } 
公共类金额
{
公共int Id{get;set;}
public AmountDetail AllList{get;set;}
公共整数TotalCount{get;set;}
公共整数Top{get;set;}
公共整型页{get;set;}
}
公共类详细信息
{
公共int名称{get;set;}
公共int姓氏{get;set;}
}
公共IHttpActionResult BildirimTumListeGetir(数量详细模型)
{
List amountDetail=新列表();
List detailList=新列表();
使用(var ctx=new ktdbEntities())
{
var query=ctx.amountList().ToList();
var count=query.count;
var total=ctx.amountListTotal(model.Id).ToList();
model.TotalCount=total.Count();

对于(var i=0;i如果要将所有amountlist添加到一个detaillist,则可以这样更改代码

public class Amount
{
    public int Id{ get; set; }
    public List<AmountDetail> AllList { get; set; }
    public int TotalCount { get; set; }
    public int Top { get; set; }
    public int Page { get; set; }
}
公共类金额
{
公共int Id{get;set;}
公共列表AllList{get;set;}
公共整数TotalCount{get;set;}
公共整数Top{get;set;}
公共整型页{get;set;}
}

否则您将匹配每个detailList->amountDetail,您应该掌握父id并找到所有linq子查询listamount和两个嵌套for循环并添加detailList。

代码中有什么错误?如何将amountDetail添加到detailList中?我想您不清楚您的要求。
TotalCount
Am上的属性count
但在代码中,您要将其添加到
模型中,即
数量详情