gpt4 book ai didi

c# - LINQ 到 SQL : Selecting Name (string) by id (smallint)

转载 作者:行者123 更新时间:2023-11-30 20:00:15 24 4
gpt4 key购买 nike

我需要检索一个 id 的名称(评估名称)

 public int GetAssessmentNo(int AssessmentNo)
{
int AssNo = (from a in contxt.View_Assessment
where a.id == AssessmentNo
select a.AssessmentName);
return AssNo;
}

无法将类型 System.Linq.IQueryable' 隐式转换为 int

最佳答案

您的查询返回一组整数。

使用其中之一:First()、Single()、FirstOrDefault()、SingleOrDefault()

public int GetAssessmentNo(int AssessmentNo)
{
int AssNo = (from a in contxt.View_Assessment
where a.id == AssessmentNo
select a).Single().AssessmentName;
return AssNo;
}

或:

public int GetAssessmentNo(int AssessmentNo)
{
int AssNo = contxt.View_Assessment.Single(a => a.id == AssessmentNo).AssessmentName;
return AssNo;
}

关于c# - LINQ 到 SQL : Selecting Name (string) by id (smallint),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21822702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com