Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在IEnumerable的末尾添加更多查询_C#_Linq - Fatal编程技术网

C# 如何在IEnumerable的末尾添加更多查询

C# 如何在IEnumerable的末尾添加更多查询,c#,linq,C#,Linq,我想将查询的一部分作为方法的参数传递 public IEnumerable<ServiceModel> Get(/*What would the type be*/ rightQuery) { IEnumerable<EntityModel> leftQuery = repository.GetAll; // the query appending might look something like this: var outcomeBefore

我想将查询的一部分作为方法的参数传递

public IEnumerable<ServiceModel> Get(/*What would the type be*/ rightQuery)
{
    IEnumerable<EntityModel> leftQuery = repository.GetAll;
    // the query appending might look something like this: 
    var outcomeBeforeMapping = leftQuery.rightQuery;

    // ...rest is not important
}

我该怎么做呢?

听起来你只是想要一个
Func
——换句话说,“给定一个查询,我会给你另一个。”

public IEnumerable Get(
Func变换)
{
IEnumerable leftQuery=repository.GetAll;
var outcomeBeforeMapping=transform(leftQuery);
...
}

您应该考虑使用<代码> IQueReaby而不是<代码> iQueDebug <代码>,如果您使用EF等,允许转换影响SQL,而不只是在本地应用。


你也应该考虑简单地把你的操作的第一部分从第二部分中分离出来——允许用户调用<代码> GETALL()/代码>,做他们想做的,然后把结果传回第二种方法。

< P>听起来你只想要一个<代码> FUNC——换句话说,“给出一个查询,我会给你另一个”。
public IEnumerable Get(
Func变换)
{
IEnumerable leftQuery=repository.GetAll;
var outcomeBeforeMapping=transform(leftQuery);
...
}

您应该考虑使用<代码> IQueReaby而不是<代码> iQueDebug <代码>,如果您使用EF等,允许转换影响SQL,而不只是在本地应用。


你也应该考虑简单地把你的操作的第一部分从第二部分中分离出来——允许用户调用<代码> GETALL()/>代码,做他们想做的,然后把结果传回第二种方法。

你是指<代码> Func RealQuest?我决不是指IQueryable。不。谢谢:)啊,IEnumerable,IQueryable,谁在乎:)希望你解决了你的问题。你是说
Func rightQuery
?我不是说IQueryable。不。谢谢:)啊,IEnumerable,IQueryable,谁在乎:)希望你解决了你的问题。为什么不IQueryable呢?@tym32167:好吧,OP目前的代码中没有
IQueryable
。但我在编辑中提到了这个选项。我没有使用实体框架,它只是对象的集合。@JonSkeet谢谢。(天哪,他回答我说,哇!谢谢你的书,让我大吃一惊:)为什么不可以IQueryable?@tym32167:好吧,OP目前的代码中没有
IQueryable
。但我在编辑中提到了这个选项。我没有使用实体框架,它只是对象的集合。@JonSkeet谢谢。(天哪,他回答我,哇!谢谢你的书,让我大吃一惊:)
service.Get((query) => query.OrderByDescending(project => project.SortOrder));
public IEnumerable<ServiceModel> Get(
    Func<IEnumerable<ServiceModel>,  IEnumerable<ServiceModel>> transform)
{
    IEnumerable<EntityModel> leftQuery = repository.GetAll;
    var outcomeBeforeMapping = transform(leftQuery);
    ...
}