+ All Categories
Home > Technology > SQL Saturday 28 - .NET Fundamentals

SQL Saturday 28 - .NET Fundamentals

Date post: 10-May-2015
Category:
Upload: mikehuguet
View: 953 times
Download: 2 times
Share this document with a friend
Description:
This is from my presentation @ 7:30 AM on August 14th at SQL Saturday 28 in Baton Rouge, LA.
Popular Tags:
31
#28 BATON ROUGE .NET Fundamentals Mike Huguet
Transcript
Page 1: SQL Saturday 28 - .NET Fundamentals

#28 BATON ROUGE

.NET FundamentalsMike Huguet

Page 2: SQL Saturday 28 - .NET Fundamentals

Solutions Architect for BRDNUG leader, http://brdnug.org MS Patterns & Practices SP Guidance

Advisor SQLSat28 Organizer

http://twitter.com/mhuguet http://geekswithblogs.com/mikehuguet

Mike Huguet

Page 3: SQL Saturday 28 - .NET Fundamentals

A.K.A – “Huggy” Bear What does he do anyway? Favorite restaurant is any $5 Chinese Buffet He only quotes movies from the 80’s

Alternate Intro

Page 4: SQL Saturday 28 - .NET Fundamentals

Introduce some of the “new” fundamentals Enhance knowledge of these fundamentals

Objectives

Face.Expression !=

Page 5: SQL Saturday 28 - .NET Fundamentals

Feature Timeline

2006 2007 2010

3.0 3.5 4.02.0

2008

3.5 SP1

Generics

• Extensions• Lambdas• LINQ

2005

Page 6: SQL Saturday 28 - .NET Fundamentals

Language specific implementation / syntax Compiler and IDE magic Increase productivity and readability /

reduce code

What’s in Common

Page 7: SQL Saturday 28 - .NET Fundamentals

?Generics

“Generics let you tailor a method, class, structure, or interface to the precise data type it acts upon.”

- MSDN

Page 8: SQL Saturday 28 - .NET Fundamentals

Generics

- MSDN

Page 9: SQL Saturday 28 - .NET Fundamentals

Native to the CLR Allow for better type safety increasing

performance (no box, unbox, casting)◦ ArrayList vs. List<T>

IDE Magic

What are Generics?

Page 10: SQL Saturday 28 - .NET Fundamentals

*200% perf gain value types (i.e.-string, int…)

*100% perf gain ref types (i.e.-MyClass) Used throughout .NET Make great containers

◦ i.e.-List<T> Activator.CreateInstance<T>()

Uses / Benefits

* - #’s from MSDN

Page 11: SQL Saturday 28 - .NET Fundamentals

C#◦ List<string> x = new List<string>();◦ String GetValueAsString<T>(T entity) {}

VB.NET◦ Dim x As New List(Of String)◦ Function GetValueAsString(of T)(ByRef entity As T) As String

Syntax

Page 12: SQL Saturday 28 - .NET Fundamentals

Demo

Page 13: SQL Saturday 28 - .NET Fundamentals

Derivation Constraints◦ class Repo<T> where T : BaseEntity◦ class Repo<T> where T : BaseEntity, IComparable<T>◦ class Repo<T, K> where T : BaseEntity

where K : IValidator

Reference/Value Type Constraints◦ class Repo<T> where T : class◦ class Repo<T> where T : struct

Constructor Constraints◦ class Repo<T> where T : class, new()

Constraints (C#)

Page 14: SQL Saturday 28 - .NET Fundamentals

Derivation Constraints◦ Class Repo(Of T As BaseEntity)◦ Class Repo(Of T As {BaseEntity, IComparable(Of T)})◦ Class Repo(Of T As BaseEntity, K As IValidator))

Reference/Value Type Constraints◦ Class Repo(Of T As Class)◦ Class Repo(Of T As Structure)

Constructor Constraints◦ Class Repo(Of T As New, Class)

Constraints (VB.NET)

Page 15: SQL Saturday 28 - .NET Fundamentals

?Extension Methods

“Extension methods enable you to ‘add’ methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.”

-MSDN

Page 16: SQL Saturday 28 - .NET Fundamentals

Allows adding methods to an existing type No recompile needed Can extend framework classes (including

sealed) Methods included in Intellisense

Extension Methods

Page 17: SQL Saturday 28 - .NET Fundamentals

Demo

Page 18: SQL Saturday 28 - .NET Fundamentals

?Lamda Expressions

“A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.”

-MSDN

Page 19: SQL Saturday 28 - .NET Fundamentals

Shorthand for a function A variable that points to function Anonymous function (no name) Returns a single value Explicit or inferred types

Return Parameter(s)

What is a Lambda Anyway?

Page 20: SQL Saturday 28 - .NET Fundamentals

C# Arg list => expression x => x + 1 (x, y) => x == y

VB.NET Function(x) x + 1 Function(x, y) x = y

Syntax Examples

Page 21: SQL Saturday 28 - .NET Fundamentals

Summary - Wherever a delegate type can be used

Event handlers LINQ Projection Extensions (Select, SelectMany) Find Extensions (Find, FindAll)

When Can We Use Them?

Page 22: SQL Saturday 28 - .NET Fundamentals

Demo

Page 23: SQL Saturday 28 - .NET Fundamentals

?Language Integrated Query (LINQ)“LINQ is a set of extensions to the .NET

Framework that encompass language-integrated query, set, and transform operations. .”

-MSDN

Page 24: SQL Saturday 28 - .NET Fundamentals

Core functionality provided by extension methods (method based)◦ Any()◦ Where()◦ OrderBy()◦ ThenBy()◦ Contains()◦ Join()◦ First()...

LINQ

Page 25: SQL Saturday 28 - .NET Fundamentals

Expression basedvar results = from process in Process.GetProcesses() where process.ProcessName.Contains("WINWORD") orderby process.MainWindowTitle descending select process;

Method based var results = Process.GetProcesses()

.Where(process=>process.ProcessName .Contains("WINWORD")) .OrderBy(x=>x.MainWindowTitle);

LINQ Options

Page 26: SQL Saturday 28 - .NET Fundamentals

Demo

Page 27: SQL Saturday 28 - .NET Fundamentals

LINQ

.NET Language – Integrated Query

C# VBOther

Languages

LINQ to Objects LINQ to

DatasetsLINQ to

SQLLINQ to Entities

LINQ to XML

Relational Data

XMLObjec

ts

LINQ enabled ADO.NET

LINQ enabled data sources

Page 28: SQL Saturday 28 - .NET Fundamentals

LINQ to … LINQ to Objects LINQ to XML (XLINQ) LINQ to DataSets LINQ to SQL (DLINQ) LINQ to Entities (EF) LINQ to SharePoint LINQ to REST LINQ to NHibernate LINQ to Twitter LINQ to SQL Saturday???

Page 29: SQL Saturday 28 - .NET Fundamentals

Feature Timeline

2006 2007 2010

3.0 3.5 4.02.0

2008

3.5 SP1

Generics

• Extensions• LINQ• Lambdas

2005

Page 30: SQL Saturday 28 - .NET Fundamentals

Key Takeaways Rich productivity improvements in the

framework and languages More to explore and learn LINQ is built on all of these You know that you want to roll your own

LINQ provider & “Extend it”

Page 31: SQL Saturday 28 - .NET Fundamentals

@SQL Saturday #28

Baton Rouge.NET FundamentalsMike Huguet - @mhuguet- [email protected]


Recommended