2012-12-28 61 views
1

只是两个快速问题Linq表达式转换

1.下面的语句叫什么?

Func<usersDto, bool> predicate 

2.与下面有什么不同?

Expression<Func<usersDto, bool>> 

3.How做我转换Func<type1,bool>Func<type2,bool>。好像先进的东西我

GetUsers(Func<UserDto,bool> predicate) 
{  
    return EfContext.Users.Where (convert above predicate to be passed here) 
         .Cast<>();  
} 
+0

问题可能已被回答。 [http://stackoverflow.com/questions/793571/why-would-you-use-expressionfunct-rather-than-funct][1] [1]:HTTP:// stackoverflow.com/questions/793571/why-would-you-use-expressionfunct-rather-than-funct – mdcuesta

+5

第一个被称为谓词。第二个没有名字,但我会称之为Al。 – SWeko

+0

@mdcuesta#2从您的链接回答,#1和#3仍然打开 – Deeptechtons

回答

3

一个Func<T, TResult>是一个内置的委托,它需要一个类型为T参数,返回类型为TResult的值。在您的问题中,predicate是代表需要usersDto的实例并返回bool

一种Expression<Func<T, TResult>>未编译Func<T, TResult>,它可以被分析,或者填充到另一表达的部分。

Q3:参见my answer for this question