Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
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 
AnswerRe: pas de dèfinition dans geolocator pour RequestAccessAsync dans windows10 Pin
OriginalGriff27-Dec-16 0:46
mveOriginalGriff27-Dec-16 0:46 
AnswerRe: pas de dèfinition dans geolocator pour RequestAccessAsync dans windows10 Pin
Patrice T27-Dec-16 22:47
mvePatrice T27-Dec-16 22:47 
QuestionEnable Mouse in c# RDP viewer Pin
Member 1289017426-Dec-16 19:53
Member 1289017426-Dec-16 19:53 
AnswerRe: Enable Mouse in c# RDP viewer Pin
Richard MacCutchan26-Dec-16 21:33
mveRichard MacCutchan26-Dec-16 21:33 
GeneralI can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 20:37
Member 1289974625-Dec-16 20:37 
QuestionRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Richard MacCutchan25-Dec-16 20:39
mveRichard MacCutchan25-Dec-16 20:39 
AnswerRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 21:05
Member 1289974625-Dec-16 21:05 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Richard MacCutchan25-Dec-16 21:13
mveRichard MacCutchan25-Dec-16 21:13 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 20:54
mveOriginalGriff25-Dec-16 20:54 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 21:07
Member 1289974625-Dec-16 21:07 
AnswerRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 21:19
mveOriginalGriff25-Dec-16 21:19 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 21:21
Member 1289974625-Dec-16 21:21 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 21:33
mveOriginalGriff25-Dec-16 21:33 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 21:37
Member 1289974625-Dec-16 21:37 

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.