25
Mohammad Shaker mohammadshaker.com @ZGTRShaker 2011, 2012, 2013, 2014 C# Advanced L06-SQL SERVER & LINQ to SQL

C# Advanced L06-SQL Server+LINQ to SQL

Embed Size (px)

DESCRIPTION

C# Advanced L06-SQL Server+LINQ to SQL

Citation preview

Page 1: C# Advanced L06-SQL Server+LINQ to SQL

Mohammad Shaker

mohammadshaker.com

@ZGTRShaker

2011, 2012, 2013, 2014

C# AdvancedL06-SQL SERVER & LINQ to SQL

Page 2: C# Advanced L06-SQL Server+LINQ to SQL

SQL ServerMicrosoft SQL Server Management Studio

Page 3: C# Advanced L06-SQL Server+LINQ to SQL

SQL Server

Page 4: C# Advanced L06-SQL Server+LINQ to SQL

Database in Visual Studio

Page 5: C# Advanced L06-SQL Server+LINQ to SQL

Database in Visual Studio

Server Explorer

Page 6: C# Advanced L06-SQL Server+LINQ to SQL

Database in Visual Studio

Page 7: C# Advanced L06-SQL Server+LINQ to SQL

Database in Visual Studio

Page 8: C# Advanced L06-SQL Server+LINQ to SQL

Database in Visual Studio

Page 9: C# Advanced L06-SQL Server+LINQ to SQL

Database Tables

Page 10: C# Advanced L06-SQL Server+LINQ to SQL

ORM

Page 11: C# Advanced L06-SQL Server+LINQ to SQL

ORMObject-Relational Mapping

Page 12: C# Advanced L06-SQL Server+LINQ to SQL

ORM and LINQObject-Relational Mapping

Page 13: C# Advanced L06-SQL Server+LINQ to SQL

LINQ to SQL

Page 14: C# Advanced L06-SQL Server+LINQ to SQL

LINQ Architecture

Page 15: C# Advanced L06-SQL Server+LINQ to SQL

Performance

• LINQ has more control and efficiency in O/R Mapping than NHibernate

– LINQ: Externl Mapping or Attribute Mapping

– NHibernate: Externl Mapping

• Because of mapping, LINQ is lower than database tools such as SqlDataReaderor SqlDataAdapter

– In large dataset, their performance are more and more similar

Page 16: C# Advanced L06-SQL Server+LINQ to SQL

Add LINQ to SQL Class

Page 17: C# Advanced L06-SQL Server+LINQ to SQL

Add LINQ to SQL Class

Page 18: C# Advanced L06-SQL Server+LINQ to SQL

Add LINQ to SQL Class

• Just drag and drop the tables and everything will be mapped

Page 19: C# Advanced L06-SQL Server+LINQ to SQL

Query with LINQ to SQLSuper Easy! You Already Know LINQ!

Page 20: C# Advanced L06-SQL Server+LINQ to SQL

Query with LINQ to SQL

public static string GetTeacherName(int TeacherId)

{

return (from teacher in _archiveDB.Teachers

where teacher.TeacherId == TeacherId

select teacher.TeacherFirstName + " " + teacher.TeacherLastName).Single();

}

Page 21: C# Advanced L06-SQL Server+LINQ to SQL

Query with LINQ to SQL

public static string GetTeacherName(int TeacherId)

{

return (from teacher in _archiveDB.Teachers

where teacher.TeacherId == TeacherId

select teacher.TeacherFirstName + " " + teacher.TeacherLastName).Single();

}

public static Lecture GetCurrentLecture(int hallId)

{

var query = (from lecture in _archiveDB.Lectures

where lecture.HallId == hallId

&& lecture.LectureDay.Equals(DateTime.Now.DayOfWeek.ToString())

&& lecture.LectureStartTime <= DateTime.Now.TimeOfDay

&& lecture.LectureEndTime >= DateTime.Now.TimeOfDay

&& lecture.LectureDay.Equals(DateTime.Now.DayOfWeek.ToString())

select lecture).Single();

return query;

}

Page 22: C# Advanced L06-SQL Server+LINQ to SQL

Live Demo

Page 23: C# Advanced L06-SQL Server+LINQ to SQL

Data-Grid, BindingWindows Forms, ASP.NET and WPF

Page 24: C# Advanced L06-SQL Server+LINQ to SQL

Data miningSQL Intelligent Suite

Page 25: C# Advanced L06-SQL Server+LINQ to SQL

Data mining Decision Trees, Clustering, …etc.