Ken*_*als 2 c# linq iqueryable linq-to-sql
我有这个代码从Alleged Perpetrator表返回一个caseID.该表还有一个"LastName"列.我想搜索caseID并返回LastName,但我不知道如何编写它.我一直在微软网站上寻找LINQ to SQL示例,但仍然无法弄明白.任何帮助将不胜感激!
肯
public static class AllegedPerpetratorRepository
{
public static IQueryable<AllegedPerpetrator> GetByCaseID(
this IQueryable<AllegedPerpetrator> source,
int caseID)
{
return (from s in source where s.CaseID.Equals(caseID) select s);
}
}
Run Code Online (Sandbox Code Playgroud)
最终应该是:
...select s.LastName);
编辑:
艾哈迈德的建议和Jeroen的解决方案:
public static class AllegedPerpetratorRepository
{
public static IEnumerable<string> GetByCaseID(
this IQueryable<AllegedPerpetrator> source,
int caseID)
{
return (from s in source where s.CaseID.Equals(caseID) select s.LastName);
}
}
Run Code Online (Sandbox Code Playgroud)