Click here to Skip to main content
15,905,427 members
Home / Discussions / C#
   

C#

 
AnswerRe: Simulate Desktop Mouse Scroll (Via C++ PInvoke) Pin
Gerry Schmitz29-Dec-16 11:13
mveGerry Schmitz29-Dec-16 11:13 
QuestionUnderstanding DbContext Class Pin
Liagapi29-Dec-16 7:00
Liagapi29-Dec-16 7:00 
AnswerRe: Understanding DbContext Class Pin
Dave Kreskowiak29-Dec-16 9:42
mveDave Kreskowiak29-Dec-16 9:42 
AnswerRe: Understanding DbContext Class Pin
John C Rayan30-Dec-16 3:21
professionalJohn C Rayan30-Dec-16 3:21 
GeneralRe: Understanding DbContext Class Pin
Liagapi30-Dec-16 5:58
Liagapi30-Dec-16 5:58 
GeneralRe: Understanding DbContext Class Pin
Jon McKee30-Dec-16 16:18
professionalJon McKee30-Dec-16 16:18 
QuestionSplit Particular Digit using C# Pin
nick70329-Dec-16 2:44
nick70329-Dec-16 2:44 
AnswerRe: Split Particular Digit using C# Pin
Pete O'Hanlon29-Dec-16 2:50
mvePete O'Hanlon29-Dec-16 2:50 
QuestionRe: Split Particular Digit using C# Pin
Peter Leow29-Dec-16 3:33
professionalPeter Leow29-Dec-16 3:33 
AnswerRe: Split Particular Digit using C# Pin
Gerry Schmitz29-Dec-16 10:49
mveGerry Schmitz29-Dec-16 10:49 
GeneralRe: Split Particular Digit using C# Pin
nick70330-Dec-16 1:48
nick70330-Dec-16 1:48 
QuestionIdle Time Pin
AnjanaPrasanth27-Dec-16 21:02
AnjanaPrasanth27-Dec-16 21:02 
AnswerRe: Idle Time Pin
OriginalGriff27-Dec-16 21:32
mveOriginalGriff27-Dec-16 21:32 
QuestionRe: Idle Time Pin
Eddy Vluggen28-Dec-16 1:35
professionalEddy Vluggen28-Dec-16 1:35 
AnswerRe: Idle Time Pin
Gerry Schmitz28-Dec-16 6:09
mveGerry Schmitz28-Dec-16 6:09 
AnswerRe: Idle Time Pin
Dave Kreskowiak28-Dec-16 6:35
mveDave Kreskowiak28-Dec-16 6:35 
GeneralRe: Idle Time Pin
Gerry Schmitz29-Dec-16 10:22
mveGerry Schmitz29-Dec-16 10:22 
QuestionExpressions In C# Pin
Liagapi27-Dec-16 11:30
Liagapi27-Dec-16 11:30 
AnswerRe: Expressions In C# Pin
Midi_Mick27-Dec-16 12:56
professionalMidi_Mick27-Dec-16 12:56 
GeneralRe: Expressions In C# Pin
Liagapi27-Dec-16 15:50
Liagapi27-Dec-16 15:50 
GeneralRe: Expressions In C# Pin
Simon_Whale27-Dec-16 23:23
Simon_Whale27-Dec-16 23:23 
AnswerRe: Expressions In C# Pin
Jon McKee27-Dec-16 17:14
professionalJon McKee27-Dec-16 17:14 
Expression<Func<T, TResult>> represents a strongly-typed expression tree of a lambda or function. Expression trees represent expressions like a < b stored in a tree structure. So what are they used for? Well, that's open to your imagination honestly. A common scenario is if you want to modify a code expression based on some currently unknown or later business logic. Since an expression tree is a data representation of a code expression you're free to modify it before calling Compile() and executing it. This is essential for LINQ-to-SQL which transforms expressions like from a in db.table select a into an expression tree which is then transformed into the necessary SQL for the actual DB call. Expression trees are also heavily used in the Dynamic Language Run-time.

As far as the specific example in your other post:
C#
public IEnumerable<T> Find(Expression<Func<T, bool>> predicate)
{
   return Context.Set<T>().Where(predicate);
}
Context is most likely a DbContext object. Set<T>() returns a DbSet<T> of all entities of the type given to Set. Then Where is called to filter the result based on the predicate expression which, instead of just being a lambda, is stored as an expression tree - I'm guessing because of some other logic elsewhere in the application otherwise this seems a little over-the-top.

EDIT: Forgot to add how to use them. In LINQ you treat it like any other function. Outside of LINQ you call Compile() to create the Func delegate. To create them is as simple as assigning a lambda in simple cases. For example, Expression<Func<int,int>> incrementTree = a => a + 1;. In more complex cases, you may need to explicitly use the expression tree API which you can find links to in the MSDN guide below.

Further reading:
Expression Tree Basics
Expression Trees - MSDN
PraiseRe: Expressions In C# Pin
John C Rayan30-Dec-16 3:29
professionalJohn C Rayan30-Dec-16 3:29 
SuggestionRe: Expressions In C# Pin
John C Rayan30-Dec-16 4:31
professionalJohn C Rayan30-Dec-16 4:31 
Questionpas de dèfinition dans geolocator pour RequestAccessAsync dans windows10 Pin
Member 865861426-Dec-16 23:44
Member 865861426-Dec-16 23:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.