使用LINQ检索相关数据



我首先使用EF代码具有MVC应用程序。我将用户添加到系统中并输入养老金详细信息,其中一部分是链接到称为PensionBeneFitlevel的模型的下拉列表。这是模型 -

[Key]
public int PensionBenefitLevelID { get; set; }
public string DisplayText { get; set; }
public int EmployeePercentage { get; set; }
public int EmployerPercentage { get; set; }
public virtual ICollection<Pension> Pension { get; set; }

注册时,我有来自下拉列表的pensionBeneFitlevelID,但是在我的控制器中,我要使用与该ID相关的雇主PerperCentage值进行计算。谁能指向正确的方向?

我是否需要在控制器中创建一个变量并使用LINQ查询来获得该值?我找不到类似事物的任何例子,所以如果您可以指出我也很棒的示例。

如果我正确理解了问题,您想恢复对应于PensionBenefitLevelID的实体并在EmployerPercentage字段上执行计算。

由于您尚未提及与EF(存储库,工作单位等)使用的模式,所以我只能给您一个一般答案:

var entity = [Your DB Context].[Your Entity].GetById(pensionBenefitLevelID);
if(entity != null)
{
    [Calculation]
} 

最新更新