C# DB First方法,那么我可以在模型类或SQL Server Express中进行更改吗?@stom您的模型类是部分的,因此您可以轻松地对其进行扩展。@stom-Hi!请不要修改EF自动生成的类,您需要创建一个单独的分部类MarksType,并在其中添加

C# DB First方法,那么我可以在模型类或SQL Server Express中进行更改吗?@stom您的模型类是部分的,因此您可以轻松地对其进行扩展。@stom-Hi!请不要修改EF自动生成的类,您需要创建一个单独的分部类MarksType,并在其中添加,c#,asp.net-mvc,linq,asp.net-mvc-4,C#,Asp.net Mvc,Linq,Asp.net Mvc 4,DB First方法,那么我可以在模型类或SQL Server Express中进行更改吗?@stom您的模型类是部分的,因此您可以轻松地对其进行扩展。@stom-Hi!请不要修改EF自动生成的类,您需要创建一个单独的分部类MarksType,并在其中添加TotalMarks属性。@Rahusingh,感谢您的解决方案,我刚刚停止了此方法,因为我的要求已更改。@VMAtm,我试图在视图中显示特定学生的总分考虑@RahulSingh的答案-我认为他提供了解决您问题的正确方法。 public pa


DB First方法,那么我可以在模型类或SQL Server Express中进行更改吗?@stom您的模型类是部分的,因此您可以轻松地对其进行扩展。@stom-Hi!请不要修改EF自动生成的类,您需要创建一个单独的分部类
MarksType
,并在其中添加
TotalMarks
属性。@Rahusingh,感谢您的解决方案,我刚刚停止了此方法,因为我的要求已更改。@VMAtm,我试图在视图中显示特定学生的总分考虑@RahulSingh的答案-我认为他提供了解决您问题的正确方法。
 public partial class MarksType
 {
    public int MarksTypeId { get; set; }
    public Nullable<int> English { get; set; }
    public Nullable<int> Math { get; set; }
    public Nullable<int> Physics { get; set; }
    public Nullable<int> Chemistry { get; set; }
    public Nullable<int> ComputerScience { get; set; }
    public Nullable<int> MoralScience { get; set; }
    public Nullable<int> TotalMarks { get; set; }
  }
public class MarksController : Controller
{
    MarksEntities marks = new MarksEntities();

public ActionResult MarksProfile()
{
   List<MarksType> yourmarks = from x in marks.MarksType where x.MarksTypeId == 5
                         group x by 1 into y
                         select new MarksType
                         {   

                             English = y.Sum(x => x.English),
                             Math = y.Sum(x => x.Math),
                             Physics = y.Sum(x => x.Physics),
                             Chemistry= y.Sum(x => x.Chemistry),
                             ComputerScience = y.Sum(x => x.ComputerScience),
                             MoralScience= y.Sum(x => x.MoralScience),

                             TotalMarks = y.Sum(x => x.English) + y.Sum(x => x.Math)
                             + y.Sum(x => x.Physics) + y.Sum(x => x. Chemistry)
                             +y.Sum(x => x.ComputerScience) + y.Sum(x => x.MoralScience)
                         }).ToList();



        return View(yourmarks);
    }
}
@model IEnumerable<MvcMarks.Models.MarksType>

<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
    <th>
        @Html.DisplayNameFor(model => model. MarksTypeId)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.English)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Math)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Physics )
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Chemistry)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.ComputerScience)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.MoralScience)
    </th>
    <th></th>
</tr>

@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.MarksTypeId)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.English)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Math)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Physics )
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Chemistry)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.ComputerScience)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.MoralScience)
    </td>

    </tr>
    }

    </table>
@model IEnumerable<MvcMarks.Models.MarksType>
List<MarksType> yourmarks = (from x in marks.MarksType where x.MarksTypeId == 5
                         group x by 1 into y
                         select new MarksType
                         {      
                             MarksTypeId = .. ,
                             English = ..       
                             TotalMarks = y.Sum(x => x.English) +y.Sum(x => x.Math)
                             + y.Sum(x => x.Physics) + y.Sum(x => x. Chemistry)
                             +y.Sum(x => x.ComputerScience) + y.Sum(x => x.MoralScience)
                         }).ToList();
public partial class MarksType
{
    //other properties
    public decimal TotalMarks {get; set; }
}
 public partial class MarksTypeViewModel
 {
    public Nullable<int> English { get; set; }
    public Nullable<int> Math { get; set; }
    public Nullable<int> Physics { get; set; }
    public Nullable<int> Chemistry { get; set; }
    public Nullable<int> ComputerScience { get; set; }
    public Nullable<int> MoralScience { get; set; }
    public Nullable<int> TotalMarks { get; set; }
 }
List<MarksTypeViewModel> yourmarks = from x in marks.MarksType where x.MarksTypeId == 5
                     group x by 1 into y
                     select new MarksTypeViewModel
                     {   
                         English = y.Sum(x => x.English),
                         Math = y.Sum(x => x.Math),
                         Physics = y.Sum(x => x.Physics),
                         Chemistry= y.Sum(x => x.Chemistry),
                         ComputerScience = y.Sum(x => x.ComputerScience),
                         MoralScience= y.Sum(x => x.MoralScience),

                         TotalMarks = y.Sum(x => x.English) + y.Sum(x => x.Math)
                         + y.Sum(x => x.Physics) + y.Sum(x => x. Chemistry)
                         +y.Sum(x => x.ComputerScience) + y.Sum(x => x.MoralScience)
                     }).ToList();
@model IEnumerable<MvcMarks.Models.MarksTypeViewModel>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>