SlideShare a Scribd company logo
Ivan Marković
MSP Lead
Software Developer at SPAN d.o.o.
ivan.markovic@studentpartner.com
Vidjeli smo…
• Tipovi aplikacija
• Metode razvoja softverskog proizvoda+ALM
u Microsoft alatima
• C#
• Baze podataka
Agenda
1) Entity Framework
2) LINQ
3) EF+LINQ Demo(s)
Entity framework
What is Entity Framework?
• Entity framework is an Object/Relational
Mapping (O/RM) framework
• Automated mechanism for accessing &
storing the data in the database
What is ORM?
• ORM is a tool for storing data from domain
objects to relational database (like MS SQL
Server)
• O/RM includes three main parts: Domain
class objects, Relational database objects and
Mapping information
Why ORM?
• ORM allows us to keep our database design
separate from our domain class design
• This makes the application maintainable and
extendable
ORM vs Traditional Data Access
Techniques
• ORM often reduces the amount of code that
needs to be written
• High level of abstraction obscuring what is
actually happening in the implementation
code
Entity Framework Architecture
SQL Relationships
• One-to-Many Relationship
• Many-to-Many Relationship
• One-to-One Relationship
EF 6 Tools for VS 2012 & 2013
• http://www.microsoft.com/en-
us/download/confirmation.aspx?id=40762
Database first
• An existing database can be used
• Code can be auto-generated.
• Extensible using partial classes/ T4 templates
• The developer can update the database
manually
• There is a very good designer, which sync with
the underlining database
Code first
• There is full control of the model from the
Code; no EDMX/designer
• No manual intervention to DB is required
• The database is used for data only
• POCO Class
Model first
• Good support with EDMX designer
• We can visually create the database model
• EF generates the Code and database script
• Extensible through partial classes
• We can modify the model and update the
generated database.
Code first from existing database
• POCO Classes from existing database
Which one to choose?
• It depends on you…
LINQ
• Language-Integrated Query (LINQ)
• Set of features that extends powerful query
capabilities to the language syntax of C# and
Visual Basic.
LINQ
Three parts
• All LINQ query operations consist of three
distinct actions:
– Obtain the data source.
– Create the query.
– Execute the query.
Three parts
• // 1. Data source.
• int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
• // 2. Query creation.
• // numQuery is an IEnumerable<int>
• var numQuery =
• from num in numbers
• where (num % 2) == 0
• select num;
• // 3. Query execution.
• foreach (int num in numQuery)
• {
• Console.Write("{0,1} ", num);
• }
The Data Source
• Types that support IEnumerable<T> or a
derived interface such as the generic
IQueryable<T> are called queryable types
The Query
• The query specifies what information to
retrieve from the data source or sources
• Query also specifies how that information
should be sorted, grouped, and shaped
before it is returned
• The query expression contains three
clauses: from, where and select
Deferred execution
• query variable itself only stores the query
commands
• The actual execution of the query is deferred
until you iterate over the query variable in
a foreach statement
Forcing Immediate Execution
• Examples of such queries
are Count, Max, Average, and First. These
execute without an explicit foreach statement
because the query itself must use foreach in
order to return a result.
• That these types of queries return a single value,
not an IEnumerable collection.
• ToList<T>, ToArray<T>
LINQ vs SQL
SELECT UPPER(Name)
FROM Customer
WHERE Name LIKE 'A%'
ORDER BY Name
LINQ vs SQL
SELECT UPPER(Name) FROM
(
SELECT *, RN = row_number()
OVER (ORDER BY Name)
FROM Customer
WHERE Name LIKE 'A%'
) A
WHERE RN BETWEEN 21 AND 30
ORDER BY Name
LINQ vs SQL
var query =
from c in db.Customers
where c.Name.StartsWith ("A")
orderby c.Name
select c.Name.ToUpper();
var thirdPage = query.Skip(20).Take(10);
LINQ vs SQL
from p in db.Purchases
where p.Customer.Address.State == "WA" ||
p.Customer == null
where p.PurchaseItems.Sum (pi =>
pi.SaleAmount) > 1000
select p
LINQ vs SQL
SELECT p.*
FROM Purchase p
LEFT OUTER JOIN
Customer c INNER JOIN Address a ON c.AddressID = a.ID
ON p.CustomerID = c.ID
WHERE
(a.State = 'WA' || p.CustomerID IS NULL)
AND p.ID in
(
SELECT PurchaseID FROM PurchaseItem
GROUP BY PurchaseID HAVING SUM (SaleAmount) > 1000
)
When not to use LINQ for querying databases
• Hand-tweaked queries (especially with
optimization or locking hints)
• Queries that involve selecting into temporary
tables, then querying those tables
Query syntax vs Method syntax
• IEnumerable<int>
numQuery1 =
• from num in
numbers
• where num %
2 == 0
• orderby num
• select num;
• IEnumerable<int>
numQuery2 =
numbers.Where(num =>
num % 2 ==
0).OrderBy(n => n);
Demo
Q & A
?
What’s next?
• 6.12. – Programiranje i testiranje softverskog
proizvoda, Denis Sušac (Mono)
– Radionica: Odabir tehnologija
• 10.12. – WCF servisi, REST servisi, Načini
povezivanja i komunikacije klijenta i servisa, Leo Tot
(MSP)
Thank you!
ivan.markovic@studentpartner.com

More Related Content

What's hot

Java Tutorial Lab 3
Java Tutorial Lab 3Java Tutorial Lab 3
Java Tutorial Lab 3
Berk Soysal
 
SOQL in salesforce || Salesforce Object Query Language || Salesforce
SOQL in salesforce || Salesforce Object Query Language || SalesforceSOQL in salesforce || Salesforce Object Query Language || Salesforce
SOQL in salesforce || Salesforce Object Query Language || Salesforce
Amit Singh
 
Taras Girnyk "Debugging and Profiling distributed applications using Opentrac...
Taras Girnyk "Debugging and Profiling distributed applications using Opentrac...Taras Girnyk "Debugging and Profiling distributed applications using Opentrac...
Taras Girnyk "Debugging and Profiling distributed applications using Opentrac...
Fwdays
 
30csharp
30csharp30csharp
30csharp
Sireesh K
 
U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)
Michael Rys
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overriding
Pinky Anaya
 
Low Cost Business Intelligence Platform for MongoDB instances using MEAN stack
Low Cost Business Intelligence Platform for MongoDB instances using MEAN stackLow Cost Business Intelligence Platform for MongoDB instances using MEAN stack
Low Cost Business Intelligence Platform for MongoDB instances using MEAN stack
Avinash Kaza
 
Adbms 17 object query language
Adbms 17 object query languageAdbms 17 object query language
Adbms 17 object query language
Vaibhav Khanna
 
Managing XML documents with Epsilon
Managing XML documents with EpsilonManaging XML documents with Epsilon
Managing XML documents with Epsilon
Dimitris Kolovos
 
32sql server
32sql server32sql server
32sql server
Sireesh K
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
Arif Ullah
 
Feeding automated test by Joe Beale
Feeding automated test by Joe BealeFeeding automated test by Joe Beale
Feeding automated test by Joe Beale
QA or the Highway
 
Pa1 session 5
Pa1 session 5Pa1 session 5
Pa1 session 5
aiclub_slides
 
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression TreesExploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
rasmuskl
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
Sireesh K
 

What's hot (15)

Java Tutorial Lab 3
Java Tutorial Lab 3Java Tutorial Lab 3
Java Tutorial Lab 3
 
SOQL in salesforce || Salesforce Object Query Language || Salesforce
SOQL in salesforce || Salesforce Object Query Language || SalesforceSOQL in salesforce || Salesforce Object Query Language || Salesforce
SOQL in salesforce || Salesforce Object Query Language || Salesforce
 
Taras Girnyk "Debugging and Profiling distributed applications using Opentrac...
Taras Girnyk "Debugging and Profiling distributed applications using Opentrac...Taras Girnyk "Debugging and Profiling distributed applications using Opentrac...
Taras Girnyk "Debugging and Profiling distributed applications using Opentrac...
 
30csharp
30csharp30csharp
30csharp
 
U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overriding
 
Low Cost Business Intelligence Platform for MongoDB instances using MEAN stack
Low Cost Business Intelligence Platform for MongoDB instances using MEAN stackLow Cost Business Intelligence Platform for MongoDB instances using MEAN stack
Low Cost Business Intelligence Platform for MongoDB instances using MEAN stack
 
Adbms 17 object query language
Adbms 17 object query languageAdbms 17 object query language
Adbms 17 object query language
 
Managing XML documents with Epsilon
Managing XML documents with EpsilonManaging XML documents with Epsilon
Managing XML documents with Epsilon
 
32sql server
32sql server32sql server
32sql server
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
 
Feeding automated test by Joe Beale
Feeding automated test by Joe BealeFeeding automated test by Joe Beale
Feeding automated test by Joe Beale
 
Pa1 session 5
Pa1 session 5Pa1 session 5
Pa1 session 5
 
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression TreesExploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
 

Similar to ORM - Ivan Marković

B_110500002
B_110500002B_110500002
B_110500002
Vaibhav Chavan
 
Linq
LinqLinq
Linq
ClickExpo
 
Link quries
Link quriesLink quries
Link quries
ulfat mushtaq
 
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
Mahmoud Ouf
 
#CNX14 - Intro to Force
#CNX14 - Intro to Force#CNX14 - Intro to Force
#CNX14 - Intro to Force
Salesforce Marketing Cloud
 
Understanding LINQ in C#
Understanding LINQ in C# Understanding LINQ in C#
Understanding LINQ in C#
MD. Shohag Mia
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
Basant Medhat
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
Mahmoud Ouf
 
Intro to .NET for Government Developers
Intro to .NET for Government DevelopersIntro to .NET for Government Developers
Intro to .NET for Government Developers
Frank La Vigne
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for Developers
Michael Rys
 
Linq in C#
Linq in C#Linq in C#
Linq in C#
Umar Farooq
 
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptxSQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
antony194610
 
(ATS6-APP01) Unleashing the Power of Your Data with Discoverant
(ATS6-APP01) Unleashing the Power of Your Data with Discoverant(ATS6-APP01) Unleashing the Power of Your Data with Discoverant
(ATS6-APP01) Unleashing the Power of Your Data with Discoverant
BIOVIA
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
Speedment, Inc.
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
Malin Weiss
 
Linq
LinqLinq
Informatica overview
Informatica overviewInformatica overview
Informatica overview
karthik kumar
 
Informatica overview
Informatica overviewInformatica overview
Informatica overview
karthik kumar
 
.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14
aminmesbahi
 
Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010
David McCarter
 

Similar to ORM - Ivan Marković (20)

B_110500002
B_110500002B_110500002
B_110500002
 
Linq
LinqLinq
Linq
 
Link quries
Link quriesLink quries
Link quries
 
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
 
#CNX14 - Intro to Force
#CNX14 - Intro to Force#CNX14 - Intro to Force
#CNX14 - Intro to Force
 
Understanding LINQ in C#
Understanding LINQ in C# Understanding LINQ in C#
Understanding LINQ in C#
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
 
Intro to .NET for Government Developers
Intro to .NET for Government DevelopersIntro to .NET for Government Developers
Intro to .NET for Government Developers
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for Developers
 
Linq in C#
Linq in C#Linq in C#
Linq in C#
 
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptxSQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
 
(ATS6-APP01) Unleashing the Power of Your Data with Discoverant
(ATS6-APP01) Unleashing the Power of Your Data with Discoverant(ATS6-APP01) Unleashing the Power of Your Data with Discoverant
(ATS6-APP01) Unleashing the Power of Your Data with Discoverant
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
Linq
LinqLinq
Linq
 
Informatica overview
Informatica overviewInformatica overview
Informatica overview
 
Informatica overview
Informatica overviewInformatica overview
Informatica overview
 
.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14
 
Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010
 

More from Software StartUp Academy Osijek

ASP.NET - Ivan Marković
ASP.NET - Ivan MarkovićASP.NET - Ivan Marković
ASP.NET - Ivan Marković
Software StartUp Academy Osijek
 
XAML and WPF - Dinko Jakovljević
XAML and WPF - Dinko JakovljevićXAML and WPF - Dinko Jakovljević
XAML and WPF - Dinko Jakovljević
Software StartUp Academy Osijek
 
Internet marketing - Damir Podhorski
Internet marketing - Damir PodhorskiInternet marketing - Damir Podhorski
Internet marketing - Damir Podhorski
Software StartUp Academy Osijek
 
Team management - Tomislav Bilić
Team management - Tomislav BilićTeam management - Tomislav Bilić
Team management - Tomislav Bilić
Software StartUp Academy Osijek
 
Baze podataka i SQL - Vlatko Vlahek
Baze podataka i SQL - Vlatko VlahekBaze podataka i SQL - Vlatko Vlahek
Baze podataka i SQL - Vlatko Vlahek
Software StartUp Academy Osijek
 
Services - Leo Tot
Services - Leo TotServices - Leo Tot
Wireframing & UI design - Andrej Mlinarevic
Wireframing & UI design - Andrej MlinarevicWireframing & UI design - Andrej Mlinarevic
Wireframing & UI design - Andrej Mlinarevic
Software StartUp Academy Osijek
 
Financijski plan - Ana Marija Delic
Financijski plan - Ana Marija DelicFinancijski plan - Ana Marija Delic
Financijski plan - Ana Marija Delic
Software StartUp Academy Osijek
 
Izvori financiranja - Nina Marković
Izvori financiranja - Nina MarkovićIzvori financiranja - Nina Marković
Izvori financiranja - Nina Marković
Software StartUp Academy Osijek
 
Software Product Development - Denis Susac
Software Product Development - Denis SusacSoftware Product Development - Denis Susac
Software Product Development - Denis Susac
Software StartUp Academy Osijek
 
C# - Igor Ralić
C# - Igor RalićC# - Igor Ralić
Poslovni plan - Sunčica Oberman Peterka
Poslovni plan - Sunčica Oberman PeterkaPoslovni plan - Sunčica Oberman Peterka
Poslovni plan - Sunčica Oberman Peterka
Software StartUp Academy Osijek
 
PM, Scrum and TFS - Ivan Marković
PM, Scrum and TFS - Ivan MarkovićPM, Scrum and TFS - Ivan Marković
PM, Scrum and TFS - Ivan Marković
Software StartUp Academy Osijek
 
Uvod u aplikacije - Luka Mandić
Uvod u aplikacije - Luka MandićUvod u aplikacije - Luka Mandić
Uvod u aplikacije - Luka Mandić
Software StartUp Academy Osijek
 

More from Software StartUp Academy Osijek (14)

ASP.NET - Ivan Marković
ASP.NET - Ivan MarkovićASP.NET - Ivan Marković
ASP.NET - Ivan Marković
 
XAML and WPF - Dinko Jakovljević
XAML and WPF - Dinko JakovljevićXAML and WPF - Dinko Jakovljević
XAML and WPF - Dinko Jakovljević
 
Internet marketing - Damir Podhorski
Internet marketing - Damir PodhorskiInternet marketing - Damir Podhorski
Internet marketing - Damir Podhorski
 
Team management - Tomislav Bilić
Team management - Tomislav BilićTeam management - Tomislav Bilić
Team management - Tomislav Bilić
 
Baze podataka i SQL - Vlatko Vlahek
Baze podataka i SQL - Vlatko VlahekBaze podataka i SQL - Vlatko Vlahek
Baze podataka i SQL - Vlatko Vlahek
 
Services - Leo Tot
Services - Leo TotServices - Leo Tot
Services - Leo Tot
 
Wireframing & UI design - Andrej Mlinarevic
Wireframing & UI design - Andrej MlinarevicWireframing & UI design - Andrej Mlinarevic
Wireframing & UI design - Andrej Mlinarevic
 
Financijski plan - Ana Marija Delic
Financijski plan - Ana Marija DelicFinancijski plan - Ana Marija Delic
Financijski plan - Ana Marija Delic
 
Izvori financiranja - Nina Marković
Izvori financiranja - Nina MarkovićIzvori financiranja - Nina Marković
Izvori financiranja - Nina Marković
 
Software Product Development - Denis Susac
Software Product Development - Denis SusacSoftware Product Development - Denis Susac
Software Product Development - Denis Susac
 
C# - Igor Ralić
C# - Igor RalićC# - Igor Ralić
C# - Igor Ralić
 
Poslovni plan - Sunčica Oberman Peterka
Poslovni plan - Sunčica Oberman PeterkaPoslovni plan - Sunčica Oberman Peterka
Poslovni plan - Sunčica Oberman Peterka
 
PM, Scrum and TFS - Ivan Marković
PM, Scrum and TFS - Ivan MarkovićPM, Scrum and TFS - Ivan Marković
PM, Scrum and TFS - Ivan Marković
 
Uvod u aplikacije - Luka Mandić
Uvod u aplikacije - Luka MandićUvod u aplikacije - Luka Mandić
Uvod u aplikacije - Luka Mandić
 

Recently uploaded

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 

Recently uploaded (20)

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 

ORM - Ivan Marković

  • 1. Ivan Marković MSP Lead Software Developer at SPAN d.o.o. ivan.markovic@studentpartner.com
  • 2. Vidjeli smo… • Tipovi aplikacija • Metode razvoja softverskog proizvoda+ALM u Microsoft alatima • C# • Baze podataka
  • 3. Agenda 1) Entity Framework 2) LINQ 3) EF+LINQ Demo(s)
  • 5. What is Entity Framework? • Entity framework is an Object/Relational Mapping (O/RM) framework • Automated mechanism for accessing & storing the data in the database
  • 6. What is ORM? • ORM is a tool for storing data from domain objects to relational database (like MS SQL Server) • O/RM includes three main parts: Domain class objects, Relational database objects and Mapping information
  • 7. Why ORM? • ORM allows us to keep our database design separate from our domain class design • This makes the application maintainable and extendable
  • 8. ORM vs Traditional Data Access Techniques • ORM often reduces the amount of code that needs to be written • High level of abstraction obscuring what is actually happening in the implementation code
  • 10. SQL Relationships • One-to-Many Relationship • Many-to-Many Relationship • One-to-One Relationship
  • 11. EF 6 Tools for VS 2012 & 2013 • http://www.microsoft.com/en- us/download/confirmation.aspx?id=40762
  • 12. Database first • An existing database can be used • Code can be auto-generated. • Extensible using partial classes/ T4 templates • The developer can update the database manually • There is a very good designer, which sync with the underlining database
  • 13. Code first • There is full control of the model from the Code; no EDMX/designer • No manual intervention to DB is required • The database is used for data only • POCO Class
  • 14. Model first • Good support with EDMX designer • We can visually create the database model • EF generates the Code and database script • Extensible through partial classes • We can modify the model and update the generated database.
  • 15. Code first from existing database • POCO Classes from existing database
  • 16. Which one to choose? • It depends on you…
  • 17. LINQ
  • 18. • Language-Integrated Query (LINQ) • Set of features that extends powerful query capabilities to the language syntax of C# and Visual Basic. LINQ
  • 19. Three parts • All LINQ query operations consist of three distinct actions: – Obtain the data source. – Create the query. – Execute the query.
  • 20. Three parts • // 1. Data source. • int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 }; • // 2. Query creation. • // numQuery is an IEnumerable<int> • var numQuery = • from num in numbers • where (num % 2) == 0 • select num; • // 3. Query execution. • foreach (int num in numQuery) • { • Console.Write("{0,1} ", num); • }
  • 21. The Data Source • Types that support IEnumerable<T> or a derived interface such as the generic IQueryable<T> are called queryable types
  • 22. The Query • The query specifies what information to retrieve from the data source or sources • Query also specifies how that information should be sorted, grouped, and shaped before it is returned • The query expression contains three clauses: from, where and select
  • 23. Deferred execution • query variable itself only stores the query commands • The actual execution of the query is deferred until you iterate over the query variable in a foreach statement
  • 24. Forcing Immediate Execution • Examples of such queries are Count, Max, Average, and First. These execute without an explicit foreach statement because the query itself must use foreach in order to return a result. • That these types of queries return a single value, not an IEnumerable collection. • ToList<T>, ToArray<T>
  • 25. LINQ vs SQL SELECT UPPER(Name) FROM Customer WHERE Name LIKE 'A%' ORDER BY Name
  • 26. LINQ vs SQL SELECT UPPER(Name) FROM ( SELECT *, RN = row_number() OVER (ORDER BY Name) FROM Customer WHERE Name LIKE 'A%' ) A WHERE RN BETWEEN 21 AND 30 ORDER BY Name
  • 27. LINQ vs SQL var query = from c in db.Customers where c.Name.StartsWith ("A") orderby c.Name select c.Name.ToUpper(); var thirdPage = query.Skip(20).Take(10);
  • 28. LINQ vs SQL from p in db.Purchases where p.Customer.Address.State == "WA" || p.Customer == null where p.PurchaseItems.Sum (pi => pi.SaleAmount) > 1000 select p
  • 29. LINQ vs SQL SELECT p.* FROM Purchase p LEFT OUTER JOIN Customer c INNER JOIN Address a ON c.AddressID = a.ID ON p.CustomerID = c.ID WHERE (a.State = 'WA' || p.CustomerID IS NULL) AND p.ID in ( SELECT PurchaseID FROM PurchaseItem GROUP BY PurchaseID HAVING SUM (SaleAmount) > 1000 )
  • 30. When not to use LINQ for querying databases • Hand-tweaked queries (especially with optimization or locking hints) • Queries that involve selecting into temporary tables, then querying those tables
  • 31. Query syntax vs Method syntax • IEnumerable<int> numQuery1 = • from num in numbers • where num % 2 == 0 • orderby num • select num; • IEnumerable<int> numQuery2 = numbers.Where(num => num % 2 == 0).OrderBy(n => n);
  • 32. Demo
  • 34. What’s next? • 6.12. – Programiranje i testiranje softverskog proizvoda, Denis Sušac (Mono) – Radionica: Odabir tehnologija • 10.12. – WCF servisi, REST servisi, Načini povezivanja i komunikacije klijenta i servisa, Leo Tot (MSP)

Editor's Notes

  1. EDM (Entity Data Model): EDM consist three main parts- Conceptual model, Mapping and Storage model. Conceptual Model: The conceptual model contains the model classes and their relationships. This will be independent from your database table design. Storage Model: Storage model is the database design model which includes tables, views, stored procedures and their relationships and keys. Mapping: Mapping consist information about how the conceptual model is mapped to storage model. LINQ to Entities:LINQ to Entities is a query language used to write queries against the object model. It returns entities, which are defined in the conceptual model. You can use your LINQ skills here. Entity SQL: Entity SQL is another query language just like LINQ to Entities. However, it is a little more difficult than L2E and also the developer will need to learn it separately. Object Service:Object service is a main entry point for accessing data from the database and to return it back. Object service is responsible for materialization, which is process of converting data returned from entity client data provider (next layer) to an entity object structure. Entity Client Data Provider:The main responsibility of this layer is to convert L2E or Entity SQL queries into a SQL query which is understood by the underlying database. It communicates with the ADO.Net data provider which in turn sends or retrieves data from database. ADO.Net Data Provider:This layer communicates with database using standard ADO.Net.
  2. Student – ima jednu adresu One to many – profesor i knjiga Many to many – student kolegij