100 likes | 276 Views
.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 =
E N D
.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 varfunc = from l inProgrammingLanguage.GetAll() wherel.Paradigm.HasValue(Functional) select l; Local variable type inference varfunc = ProgrammingLanguage.GetAll() .Where(l => l.Paradigm.HasValue(Functional)) .Select(l => l); Extension methods Lambda expressions Expression Trees
Local Variable Type Inference inti = 5; string s = "Hello"; double d = 1.0; int[] numbers = new int[] {1, 2, 3}; Dictionary<int,Order> orders = new Dictionary<int,Order>(); vari = 5; var s = "Hello"; var d = 1.0; var numbers = new int[] {1, 2, 3}; var orders = new Dictionary<int,Order>(); Compiler infers the correct type from the right side
Extension Methods obj.Foo(x, y) XXX.Foo(obj, x, y) namespaceITBoxing { public static class Extensions { public static string HasValue( thisProgrammingParadigm paradigm, ProgrammingParadigm value ) { return ( paradigm & value ) != 0 } } } Extension Method Bring extensions into scope usingITBoxing IntelliSense ProgrammingParadigm paradigm = Functional & Imperative; Paradigm.HasValue(Imperative);
Lambda Expressions List<ProgrammingLanguage> langs = ProgrammingLanguage.GetAll(); List<ProgrammingLanguage> cool = langs.FindAll( delegate(ProgrammingLanguage l) { returnl.IsCool; } ); List<ProgrammingLanguage> langs = ProgrammingLanguage.GetAll(); List<ProgrammingLanguage> cool = langs.FindAll(l => l.IsCool); Lambda expression
Expression Trees Code as Data public delegate boolPredicate<T>(T item); Expression<Predicate<ProgrammingLanguage>> isCool = l => l.IsCool == true; ParameterExpression l = Expression.Parameter( typeof(ProgrammingLanguage), "l" ); Expression expr = Expression.Equal( Expression.Property(l, typeof(ProgrammingLanguage) .GetProperty("IsCool")), Expression.Constant(true)); Expression<Predicate <ProgrammingLanguage>> isCool = Expression.Lambda <Predicate<ProgrammingLanguage>>(expr, l);
LINQ & ADO.NET Entity Framework Questions?