net team
DESCRIPTION
.NET Team. LINQ & ADO.NET Entity Framework. Stefan Dobrev. GM Avaxo Ltd. http://ligaz.blogspot.com. Contents. LINQ – general stuff LINQ Providers ADO.NET Entity Framework. LINQ. Language Integrated Query. DEMO. LINQ in Action. What we saw?. Query expressions. var func = - PowerPoint PPT PresentationTRANSCRIPT
.NET Team.NET Team.NET Team.NET TeamLINQ & ADO.NET Entity FrameworkLINQ & ADO.NET Entity Framework
Stefan DobrevStefan DobrevGMGM
Avaxo Ltd.Avaxo Ltd.
http://ligaz.blogspot.com
ContentsContentsContentsContents
1.1. LINQ – general stuffLINQ – general stuff
2.2. LINQ ProvidersLINQ Providers
3.3. ADO.NET Entity FrameworkADO.NET Entity Framework
1.1. LINQ – general stuffLINQ – general stuff
2.2. LINQ ProvidersLINQ Providers
3.3. ADO.NET Entity FrameworkADO.NET Entity Framework
LINQLINQLINQLINQLanguage Integrated QueryLanguage Integrated Query
DEMODEMODEMODEMO
LINQ in ActionLINQ in ActionLINQ in ActionLINQ in Action
What we saw?What we saw?What we saw?What we saw?
varvar func = func = fromfrom l l inin ProgrammingLanguage.GetAll() ProgrammingLanguage.GetAll() wherewhere l.Paradigm.HasValue(Functional) l.Paradigm.HasValue(Functional) selectselect l; l;
varvar func = func = ProgrammingLanguage.GetAll()ProgrammingLanguage.GetAll() ..WhereWhere(l => l.Paradigm.HasValue(Functional))(l => l.Paradigm.HasValue(Functional)) ..SelectSelect(l => l);(l => l);
Query Query expressionsexpressions
Query Query expressionsexpressions
Local variable Local variable type inferencetype inferenceLocal variable Local variable type inferencetype inference
Extension Extension methodsmethods
Extension Extension methodsmethods
Lambda Lambda expressionexpression
ss
Lambda Lambda expressionexpression
ss
Expression Expression TreesTrees
Expression Expression TreesTrees
Local Variable Type InferenceLocal Variable Type InferenceLocal Variable Type InferenceLocal Variable Type Inference
int i = 5;int i = 5;string s = "Hello";string s = "Hello";double d = 1.0;double d = 1.0;int[] numbers = new int[] {1, 2, 3};int[] numbers = new int[] {1, 2, 3};Dictionary<int,Order> orders = new Dictionary<int,Order> orders = new Dictionary<int,Order>();Dictionary<int,Order>();
var i = 5;var i = 5;var s = "Hello";var s = "Hello";var d = 1.0;var d = 1.0;var numbers = new int[] {1, 2, 3};var numbers = new int[] {1, 2, 3};var orders = new var orders = new Dictionary<int,Order>();Dictionary<int,Order>();
Compiler infers the Compiler infers the correct type from the correct type from the
right sideright side
Compiler infers the Compiler infers the correct type from the correct type from the
right sideright side
Extension MethodsExtension MethodsExtension MethodsExtension Methods
namespacenamespace ITBoxing ITBoxing{{ public static classpublic static class Extensions Extensions {{ public static string public static string HasValue(HasValue( thisthis ProgrammingParadigm paradigm, ProgrammingParadigm paradigm, ProgrammingParadigm value ) ProgrammingParadigm value ) {{ returnreturn ( paradigm & value ) != 0 ( paradigm & value ) != 0 }} }}}}
Bring Bring extensions into extensions into
scopescope
Bring Bring extensions into extensions into
scopescopeusingusing ITBoxing ITBoxing
ProgrammingParadigm paradigm = Functional & Imperative;ProgrammingParadigm paradigm = Functional & Imperative;Paradigm.HasValue(Imperative);Paradigm.HasValue(Imperative);
obj.Foo(x, y)obj.Foo(x, y)
XXX.Foo(obj, x, y)XXX.Foo(obj, x, y)
obj.Foo(x, y)obj.Foo(x, y)
XXX.Foo(obj, x, y)XXX.Foo(obj, x, y)
IntelliSensIntelliSensee
IntelliSensIntelliSensee
Extension Extension MethodMethod
Extension Extension MethodMethod
Lambda ExpressionsLambda ExpressionsLambda ExpressionsLambda Expressions
List<ProgrammingLanguage> langs = List<ProgrammingLanguage> langs = ProgrammingLanguage.GetAll();ProgrammingLanguage.GetAll();List<ProgrammingLanguage> cool =List<ProgrammingLanguage> cool = langs.FindAll(langs.FindAll( delegatedelegate(ProgrammingLanguage l)(ProgrammingLanguage l) {{ returnreturn l.IsCool; l.IsCool; } } ););
List<ProgrammingLanguage> langs = List<ProgrammingLanguage> langs = ProgrammingLanguage.GetAll();ProgrammingLanguage.GetAll();List<ProgrammingLanguage> cool =List<ProgrammingLanguage> cool = langs.FindAll(l => l.IsCool);langs.FindAll(l => l.IsCool);
Lambda expressionLambda expressionLambda expressionLambda expression
Expression TreesExpression TreesExpression TreesExpression TreesCode as DataCode as Data
Expression<Predicate<ProgrammingLanguage>>Expression<Predicate<ProgrammingLanguage>> isCool = l => l.IsCool == true;isCool = l => l.IsCool == true;
public delegate bool public delegate bool Predicate<T>(T item);Predicate<T>(T item);
ParameterExpression l = ParameterExpression l = Expression.Parameter(Expression.Parameter( typeoftypeof(ProgrammingLanguage), "l" );(ProgrammingLanguage), "l" );
Expression expr = Expression expr = Expression.Equal(Expression.Equal( Expression.Property(l, Expression.Property(l, typeof(ProgrammingLanguage)typeof(ProgrammingLanguage) .GetProperty("IsCool")), .GetProperty("IsCool")), Expression.Constant(true));Expression.Constant(true)); Expression<PredicateExpression<Predicate<ProgrammingLanguage>> isCool = <ProgrammingLanguage>> isCool = Expression.LambdaExpression.Lambda <Predicate<ProgrammingLanguage>>(expr, l);<Predicate<ProgrammingLanguage>>(expr, l);
LINQ & LINQ & ADO.NET Entity FrameworkADO.NET Entity FrameworkLINQ & LINQ & ADO.NET Entity FrameworkADO.NET Entity Framework
Questions?Questions?Questions?Questions?