C# Advanced L06-SQL Server+LINQ to SQL

Preview:

DESCRIPTION

C# Advanced L06-SQL Server+LINQ to SQL

Citation preview

Mohammad Shaker

mohammadshaker.com

@ZGTRShaker

2011, 2012, 2013, 2014

C# AdvancedL06-SQL SERVER & LINQ to SQL

SQL ServerMicrosoft SQL Server Management Studio

SQL Server

Database in Visual Studio

Database in Visual Studio

Server Explorer

Database in Visual Studio

Database in Visual Studio

Database in Visual Studio

Database Tables

ORM

ORMObject-Relational Mapping

ORM and LINQObject-Relational Mapping

LINQ to SQL

LINQ Architecture

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

Add LINQ to SQL Class

Add LINQ to SQL Class

Add LINQ to SQL Class

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

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

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();

}

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;

}

Live Demo

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

Data miningSQL Intelligent Suite

Data mining Decision Trees, Clustering, …etc.