SlideShare a Scribd company logo
THE .NET FRAMEWORK
ENTITY FRAMEWORK
Mr. Jibran Rasheed Khan
What is .NET?
• .NET is a platform that provides a standardized set of services.
• A specific software framework
• Includes a common runtime
• Programming model for .NET
• Platform for running .NET managed code in a virtual machine
• Provides a very good environment to develop networked
applications and Web Services
• Provides programming API and unified language-independent
development framework
The .Net Framework
• .Net Framework is software technology
developed by Microsoft to create
applications for Windows and Web
applications.
• It includes Framework Class Library (FCL)
and provides language interoperability
across several programming languages.
• Programs execute in a software
environment - Common Language Runtime
(CLR), an application virtual machine.
The .Net Framework
Architecture
• Common Language Specification (CLS)
are guidelines, that language should follow for
communicating with other .NET languages in a
seamless manner. (does mapping)
• Common Type System (CTS) is a base class
library that contains all type information
like Int32, Int64, String , Boolean etc.
• Common Language Runtime (CLR) is the
execution engine for .NET applications and
serves as the interface between .NET
applications and the operating system.
The Core of .Net Framework
• Common Language Runtime
• Garbage collection
• Language integration
• Multiple versioning support
• Integrated security
• Framework Class Library
• Provides the core functionality:
ASP.NET, Web Services, ADO.NET, Windows Forms, IO, XML, etc
.NET Framework
Common Language Runtime
• Manages running code – like a virtual machine
• Threading
• Memory management
• No interpreter: JIT-compiler produces native code – during the program
installation or at run time
• Fine-grained evidence-based security
• Code access security
• Code can be verified to guarantee type safety
• No unsafe casts, no un-initialized variables and no out-
of-bounds array indexing
• Role-based security
.NET Framework
Common Language Runtime
.NET Framework
Managed Code
• Code that targets the CLR is referred to as managed code
• All managed code has the features of the CLR
• Object-oriented
• Type-safe
• Cross-language integration
• Cross language exception handling
• Multiple version support
• Managed code is represented in special Intermediate Language
(IL)
.NET Framework
Automatic Memory Management
• The CLR manages memory for managed code
• All allocations of objects and buffers made from a Managed Heap
• Unused objects and buffers are cleaned up automatically through
Garbage Collection
• Some of the worst bugs in software development are not
possible with managed code
• Leaked memory or objects
• References to freed or non-existent objects
• Reading of uninitialized variables
• Pointerless environment
.NET Framework
Multiple Language Support
• .NET languages are compiled to an Intermediate Language (IL)
• IL is also known as MSIL or CIL
• CLR compiles IL in just-in-time (JIT) manner – each function is
compiled just before execution
• The JIT code stays in memory for subsequent calls
• Recompilations of assemblies are also possible
.NET Framework
Intermediate Language
• IL (MSIL or CIL) – Intermediate Language
• It is low-level (machine) language, like Assembler, but is Object-oriented
• CTS is a rich type system built into the CLR
• Implements various types (int, float, string, …)
• And operations on those types
• CLS is a set of specifications that all languages and libraries need
to follow
• This will ensure interoperability between languages
.NET Framework
Common Language Specification (CLS)
• All .NET languages have the same primitive data types. An int in
C# is the same as an int in VB.NET
• When communicating between modules written in any .NET
language, the types are guaranteed to be compatible on the
binary level
• Types can be:
• Value types – passed by value, stored in the stack
• Reference types – passed by reference, stored in the heap
• Strings are a primitive data type now
.NET Framework
Programming Languages
• Languages provided by Microsoft
• C++, C#, J#, VB.NET, JScript
• Third-parties languages
• Perl, Python, Pascal, APL, COBOL, Eiffel, Haskell, ML, Oberon, Scheme,
Smalltalk…
• Advanced multi-language features
• Cross-language inheritance and exceptions handling
• Object system is built in, not bolted on
• No additional rules or API to learn
.NET Framework
Programming Language: C#
• Mixture between C++, Java and Delphi
• Component-oriented
• Properties, Methods, Events
• Attributes, XML documentation
• All in one place, no header files, IDL, etc.
• Can be embedded in ASP+ pages
• Everything really is an object
• Primitive types aren’t magic
• Unified type system == Deep simplicity
• Improved extensibility and reusability
The .NET Framework
Common Language Runtime
• CLR manages code execution at runtime
• Memory management, thread management, etc.
Operating System
Common Language Runtime
.NET Framework
Base Class Library
• Object-oriented collection of reusable types
• Collections, I/O, Strings, etc.
Operating System
Common Language Runtime
.NET Framework (Base Class Library)
.NET Framework
Data Access Layer
• Access relational databases
• Disconnected data model
• Work with XML
Operating System
Common Language Runtime
.NET Framework (Base Class Library)
ADO .NET and XML
.NET Framework
ASP.NET & Windows Forms
• Access relational databases
• Disconnected data model
• Work with XML
Operating System
Common Language Runtime
.NET Framework (Base Class Library)
ADO .NET and XML
ASP .NET
Web Forms Web Services
Mobile Internet Toolkit
Windows
Forms
The .NET Framework
Common Language Specification
• Support wide range of
programming languages
• Use your favorite language
Operating System
Common Language Runtime
.NET Framework (Base Class Library)
ADO .NET and XML
ASP .NET
Web Forms Web Services
Mobile Internet Toolkit
Windows
Forms
C++ C# VB.NET Perl J# …
The .NET Framework
C# and Visual Studio .Net
Operating System
Common Language Runtime
.NET Framework (Base Class Library)
ADO .NET and XML
ASP .NET
Web Forms Web Services
Mobile Internet Toolkit
Windows
Forms
Common Language Specification
C++ C# VB Perl J# …
Visual
Studio
.NET
• Visual Studio .Net
is an Integrated
Development Environment
(IDE), a collection of
development tools exposed
through a common user
interface
The .NET Framework
Standards Compliance
Operating System
Common Language Runtime
.NET Framework (Base Class Library)
ADO .NET and XML
ASP .NET
Web Forms Web Services
Mobile Internet Toolkit
Windows
Forms
Common Language Specification
C++ C# VB Perl J# …
Visual
Studio
.NET
Prog. Language
Submitted to ECMA
Web services –
XML, SOAP-based
XML-based
data access
Open Language
Specification
ENTITY FRAMEWORK
ENTITY FRAMEWORK
WHAT IS?
• Entity Framework was released in 2008, Microsoft's primary means of interacting between .NET
applications and relational databases
• It is a set of ADO.NET technologies that aid in developing data-driven software.
• It is an Object Relational Mapping (ORM) framework that allows an automated way to store and
access databases. The data access framework to bridge the gap between data structures and
objects in the applications.
• It is available as part of the .NET development (version 3.5 SP1 and later)
• Microsoft’s latest and recommended way for data access for .NET applications.
• It allows to develop and maintain data-oriented apps with less code than traditional applications
• It eliminates the majority of the data-access code that must routinely write.
• It won’t need to know about the underlying database tables and columns where data need to store
ENTITY FRAMEWORK
HIGH LEVEL VIEW
ENTITY FRAMEWORK
VERSION HISTORY
ADO.NET Entity
Framework Version
Supported
Framework & IDE
Features Detail
6.0
.NET Framework 4.5.1
and Visual Studio 2013
• Async Query and Save
• Code-Based Configuration
• Dependency Resolution
• Interception/SQL logging
• Improved Connection Management
• Improved Transaction Support
5.0
.NET Framework 4.5 and
Visual Studio 2012
• Enum Support in Code First and EF Designer
• Spatial Data Types in Code First and EF
Designer
• Table-Valued Functions
• Multiple Diagrams per Model
ENTITY FRAMEWORK
VERSION HISTORY
ADO.NET Entity
Framework Version
Supported
Framework & IDE
Features Detail
4.3
.NET Framework 4.0
and Visual Studio 2010
Code First Migrations
Automatic Migrations
4.2
.NET Framework 4.0
and Visual Studio 2010
The EF 4.2 release included the bug fixes to
EF 4.1
4.1
.NET Framework 4.0
and Visual Studio 2010
Code First development
Introduced DbContext API
Data Annotations and Fluent API Validation
ENTITY FRAMEWORK
VERSION HISTORY
ADO.NET Entity
Framework Version
Supported
Framework & IDE
Features Detail
4.0
.NET Framework 4.0
and Visual Studio 2010
Model-first development
POCO support
Lazy Loading
T4 Code Generation
3.5
.NET Framework 3.5
SP1 and Visual Studio
2008 SP1
This release provided basic O/RM support
using the Database first development
ENTITY FRAMEWORK
ARCHITECTURE
• EDM, Consists of Conceptual model, Mapping and Storage model.
• LINQ to Entities, Used to write queries against the object
model.
• Entity SQL, like L2E, but little more difficult.
• Object Service, Responsible for materialization.
• ECDP, Responsible to convert L2E or Entity SQL queries into a SQL
query.
• ADO.net, Communicates with the database using standard ADO
ENTITY FRAMEWORK
ENTITY TYPES
• POCO Entities (Plain Old CLR Object)
POCO entities (also known as persistence-ignorant objects) support most of the same
query, insert, update, and delete behaviors as entity types that are generated by the
Entity Data Model. A POCO entity is a class that doesn't depend on any framework-specific
base class. It is like any other normal .NET CLR class, which is why it is called "Plain Old
CLR Objects".
• Dynamic Proxy Entities (POCO Proxy)
When creating instances of POCO entity types, the Entity Framework often creates
instances of a dynamically generated derived type that acts as a proxy for the entity. IT
can also be said that it is a runtime proxy classes like a wrapper class of POCO entity.
Dynamic Proxy is a runtime proxy class which wraps POCO entity. Dynamic proxy entities
allow lazy loading.
ENTITY FRAMEWORK
LAZY LOADING
Lazy Loading is the strategy to identify resources as non-
blocking (non-critical) and load them only when needed.
It is the default behavior of Entity Framework, which means that the related
entities or child entities are loaded only when it is being accessed for the first
time. That means in simple words we can say that Lazy loading simply delays the
loading of related entities until you specifically request it.
ENTITY FRAMEWORK
ENTITY PROPERTY
Entities mainly consist of two types
1. Scalar Property
Scalar properties are those properties that are primitive. It maps a column in a database table that
stores the data. E.g., student id, student name, class are the scalar property of a student entity.
2. Navigation Property
This property is responsible for the relationship of one entity to another. There are two types of
navigation properties:
i) Reference Navigation Property
When an entity has the property of another type of entity property, it is called reference navigation
property. It points to a single entity but represents the multiplicity of one.
ii) Collective Navigation Property
When an entity has the property of generic collection type, it is known as collective navigation
property. It has the multiplicity of many.
ENTITY FRAMEWORK
ENTITY STATES
• The entity framework API maintains the state of each entity during its lifetime. Each entity has a
state based on the operation performed on it via the context class. The entity state represented by
an enum System.Data.Entity.EntityState.
• The entity framework API builds and executes the INSERT, UPDATE, and DELETE commands based
on the state of an entity when the context.SaveChanges() method is called.
• The Context class not only holds the reference to all the entity objects as soon as retrieved from
the database, also keeps track of entity states.
• The change in entity state from the Unchanged to the Modified state is the only state that's
automatically handled by the context.
• All other changes made explicitly by using methods of DbContext or DbSet.
• Entity States
• Added
• Modified
• Deleted
• Unchanged
• Detached
ENTITY FRAMEWORK
ENTITY STATES
ENTITY FRAMEWORK
APPROACHES
DATABASE FIRST
Model the database artifacts
(tables, views, primary keys,
foreign keys, etc.)
Allows you to use legacy database
in your ORM application
Low level control over the
database
Entity Data Model can be updated
whenever database schema
changes.
Database-first approach supports
stored procedure, view, etc.
MODEL FIRST
Creating a model using the Entity
Framework designer tools
Designer can generate DDL
statements to create the database
An easy-to-use UI allows quickly
create new entities
Separation of code and database in
a declarative format
Dropping and re-creating the
database is not a choice
This uses an .EDMX file to store
model and mapping information.
CODE FIRST
The primary focus is getting the
code and logic
Define entity model with classes
and mappings in code..
Entity Framework create (and
recreate) the database for you.
Does not use Entity Framework
visual design tool, neither to design
entities
There is no XML file – no EDMX file –
to represent model and storage
schemas
ENTITY FRAMEWORK
CHOOSING RIGHT WORK MODEL
ENTITY FRAMEWORK
WORKFLOW
ENTITY FRAMEWORK
FEATURES
• Multiple DB Support
Works with a variety both relational and non-relational
servers including Microsoft SQL, MySql, Oracle, and DB2.
• Cross-platform
a cross-platform framework which can run on Windows,
Linux and Mac
• Modelling
creates an EDM based on POCO (Plain Old CLR Object)
entities with get/set properties of different data types.
• Querying
use LINQ and SQL queries to retrieve data from the
underlying relational database.
• Change Tracking
keeps track of changes occurred to instances of entities
(Property values)
• Saving
executes INSERT, UPDATE, and DELETE commands when
call the SaveChanges() and SaveChangesAsync() method
• Concurrency
Optimistic Concurrency by default to protect
overwriting changes made by another user
• Transactions
performs automatic transaction management while
querying or saving data.
• Caching
repeated querying will return data from the cache
instead of hitting the database.
• Built-in Conventions
follows conventions over the configuration which
automatically configure the EF model.
• Configurations
allows us to configure the EF model by using data
annotation attributes or Fluent API
• Migrations
commands can be executed on the NuGet Package
Manager Console or CLI to create or manage underlying
database Schema.
ENTITY FRAMEWORK
ADVANTAGES
• Reduced development time
• Developers can work more application-centric
• Free from hard-coded dependencies on a particular data engine
• Mappings can be change without changing the application code
• L2Eprovides validation for writing queries against a conceptual model
• Integrates with all the .NET application programming models
• Worked well with ASP.NET, WPF, WCF, and WCF Data Services
DATABASE FIRST
PICTORIAL TOUR
HOW TOs
The steps involved in this example are as follows:
Create the new SQL Server database
Create the database objects
Create a new C# Class Library Project in Visual Studio 2012 Solution
Add a new ADO.NET Entity Data Model to project
Create a new Database Connection
Import the database objects into the EDM
Modify the EDM to accommodate the scalar-valued functions
01
02
03
04 05
06
07 08
09
12
11
10
Features
Advantages
MODEL FIRST
PICTORIAL TOUR
HOW TOs
The steps involved in this example are as follows:
Creating the model
Creating entities in the .edmx
Editing entity properties
Applying relationships to the entities
 Name DatabaseSchema
Generating the database from the model
01 03
02
06
05
04
09
08
07
10
11
12
15
14
13
16 17 18
19 20 21
Features
Advantages
CODE FIRST
PICTORIAL TOUR
HOW TOs
The steps involved in this example are as follows:
Create a new Class Library
Create POCO (Plain Old CLR Object) classes
Add data annotations to the POCO classes.
Create enum classes (if required)
Add Entity Framework to the Solution
Add a DbContext class
Add ‘Code First Migrations’
Updates the database (if needed/made changes)
01 02
03
04
04 05
06
07
FEATURES
ADVANTATES
Question & Answer
“A wise man can learn more from a foolish question than a fool can
learn from a wise answer.”
Bruce Lee
THANK YOU
Have Great Time
Ad

More Related Content

Similar to Lecture - The .Net Technology and Framework (20)

DOT Net overview
DOT Net overviewDOT Net overview
DOT Net overview
chandrasekhardesireddi
 
Net framework
Net frameworkNet framework
Net framework
Mahfuz1061
 
NETOverview1.ppt c# using asp.net activeX data object and XNL
NETOverview1.ppt c# using asp.net activeX data object and XNLNETOverview1.ppt c# using asp.net activeX data object and XNL
NETOverview1.ppt c# using asp.net activeX data object and XNL
sagar490070
 
.Net framework
.Net framework.Net framework
.Net framework
sanya6900
 
Manas
ManasManas
Manas
Manish Manic
 
NETOverview1.ppt
NETOverview1.pptNETOverview1.ppt
NETOverview1.ppt
VivekRaj101435
 
NETOverview1ppt.pptx
NETOverview1ppt.pptxNETOverview1ppt.pptx
NETOverview1ppt.pptx
charusharma165
 
.Net framework
.Net framework.Net framework
.Net framework
baabtra.com - No. 1 supplier of quality freshers
 
Overview of microsoft dot net platforms
Overview of microsoft dot net platformsOverview of microsoft dot net platforms
Overview of microsoft dot net platforms
Abhijit B.
 
dot net final year project in jalandhar
dot net final year project in jalandhardot net final year project in jalandhar
dot net final year project in jalandhar
deepikakaler1
 
.Net final year project in jalandhar
.Net final year project in jalandhar.Net final year project in jalandhar
.Net final year project in jalandhar
deepikakaler1
 
.Net Introduction
.Net Introduction.Net Introduction
.Net Introduction
Muzzammil Wani
 
dot net technology
dot net technologydot net technology
dot net technology
Imran Khan
 
.Net overview
.Net overview.Net overview
.Net overview
AWADHESH PRATAP SINGH UNIVERSITY, REWA (M.P.)
 
.Net overviewrajnish
.Net overviewrajnish.Net overviewrajnish
.Net overviewrajnish
Rajnish Kalla
 
Introduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutionsIntroduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutions
Quontra Solutions
 
VB IMPORTANT QUESTION
VB IMPORTANT QUESTIONVB IMPORTANT QUESTION
VB IMPORTANT QUESTION
FAREED UR RAHMAN .
 
.Net overview
.Net overview.Net overview
.Net overview
teach4uin
 
.Net Framework & Languages Supported by .Net Frmaework
.Net Framework & Languages Supported by .Net Frmaework.Net Framework & Languages Supported by .Net Frmaework
.Net Framework & Languages Supported by .Net Frmaework
Pranil Dukare
 
VB.Net-Introduction.ppt
VB.Net-Introduction.pptVB.Net-Introduction.ppt
VB.Net-Introduction.ppt
BharathiLakshmiAAssi
 

Recently uploaded (20)

Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Ad

Lecture - The .Net Technology and Framework

  • 1. THE .NET FRAMEWORK ENTITY FRAMEWORK Mr. Jibran Rasheed Khan
  • 2. What is .NET? • .NET is a platform that provides a standardized set of services. • A specific software framework • Includes a common runtime • Programming model for .NET • Platform for running .NET managed code in a virtual machine • Provides a very good environment to develop networked applications and Web Services • Provides programming API and unified language-independent development framework
  • 3. The .Net Framework • .Net Framework is software technology developed by Microsoft to create applications for Windows and Web applications. • It includes Framework Class Library (FCL) and provides language interoperability across several programming languages. • Programs execute in a software environment - Common Language Runtime (CLR), an application virtual machine.
  • 4. The .Net Framework Architecture • Common Language Specification (CLS) are guidelines, that language should follow for communicating with other .NET languages in a seamless manner. (does mapping) • Common Type System (CTS) is a base class library that contains all type information like Int32, Int64, String , Boolean etc. • Common Language Runtime (CLR) is the execution engine for .NET applications and serves as the interface between .NET applications and the operating system.
  • 5. The Core of .Net Framework • Common Language Runtime • Garbage collection • Language integration • Multiple versioning support • Integrated security • Framework Class Library • Provides the core functionality: ASP.NET, Web Services, ADO.NET, Windows Forms, IO, XML, etc
  • 6. .NET Framework Common Language Runtime • Manages running code – like a virtual machine • Threading • Memory management • No interpreter: JIT-compiler produces native code – during the program installation or at run time • Fine-grained evidence-based security • Code access security • Code can be verified to guarantee type safety • No unsafe casts, no un-initialized variables and no out- of-bounds array indexing • Role-based security
  • 8. .NET Framework Managed Code • Code that targets the CLR is referred to as managed code • All managed code has the features of the CLR • Object-oriented • Type-safe • Cross-language integration • Cross language exception handling • Multiple version support • Managed code is represented in special Intermediate Language (IL)
  • 9. .NET Framework Automatic Memory Management • The CLR manages memory for managed code • All allocations of objects and buffers made from a Managed Heap • Unused objects and buffers are cleaned up automatically through Garbage Collection • Some of the worst bugs in software development are not possible with managed code • Leaked memory or objects • References to freed or non-existent objects • Reading of uninitialized variables • Pointerless environment
  • 10. .NET Framework Multiple Language Support • .NET languages are compiled to an Intermediate Language (IL) • IL is also known as MSIL or CIL • CLR compiles IL in just-in-time (JIT) manner – each function is compiled just before execution • The JIT code stays in memory for subsequent calls • Recompilations of assemblies are also possible
  • 11. .NET Framework Intermediate Language • IL (MSIL or CIL) – Intermediate Language • It is low-level (machine) language, like Assembler, but is Object-oriented • CTS is a rich type system built into the CLR • Implements various types (int, float, string, …) • And operations on those types • CLS is a set of specifications that all languages and libraries need to follow • This will ensure interoperability between languages
  • 12. .NET Framework Common Language Specification (CLS) • All .NET languages have the same primitive data types. An int in C# is the same as an int in VB.NET • When communicating between modules written in any .NET language, the types are guaranteed to be compatible on the binary level • Types can be: • Value types – passed by value, stored in the stack • Reference types – passed by reference, stored in the heap • Strings are a primitive data type now
  • 13. .NET Framework Programming Languages • Languages provided by Microsoft • C++, C#, J#, VB.NET, JScript • Third-parties languages • Perl, Python, Pascal, APL, COBOL, Eiffel, Haskell, ML, Oberon, Scheme, Smalltalk… • Advanced multi-language features • Cross-language inheritance and exceptions handling • Object system is built in, not bolted on • No additional rules or API to learn
  • 14. .NET Framework Programming Language: C# • Mixture between C++, Java and Delphi • Component-oriented • Properties, Methods, Events • Attributes, XML documentation • All in one place, no header files, IDL, etc. • Can be embedded in ASP+ pages • Everything really is an object • Primitive types aren’t magic • Unified type system == Deep simplicity • Improved extensibility and reusability
  • 15. The .NET Framework Common Language Runtime • CLR manages code execution at runtime • Memory management, thread management, etc. Operating System Common Language Runtime
  • 16. .NET Framework Base Class Library • Object-oriented collection of reusable types • Collections, I/O, Strings, etc. Operating System Common Language Runtime .NET Framework (Base Class Library)
  • 17. .NET Framework Data Access Layer • Access relational databases • Disconnected data model • Work with XML Operating System Common Language Runtime .NET Framework (Base Class Library) ADO .NET and XML
  • 18. .NET Framework ASP.NET & Windows Forms • Access relational databases • Disconnected data model • Work with XML Operating System Common Language Runtime .NET Framework (Base Class Library) ADO .NET and XML ASP .NET Web Forms Web Services Mobile Internet Toolkit Windows Forms
  • 19. The .NET Framework Common Language Specification • Support wide range of programming languages • Use your favorite language Operating System Common Language Runtime .NET Framework (Base Class Library) ADO .NET and XML ASP .NET Web Forms Web Services Mobile Internet Toolkit Windows Forms C++ C# VB.NET Perl J# …
  • 20. The .NET Framework C# and Visual Studio .Net Operating System Common Language Runtime .NET Framework (Base Class Library) ADO .NET and XML ASP .NET Web Forms Web Services Mobile Internet Toolkit Windows Forms Common Language Specification C++ C# VB Perl J# … Visual Studio .NET • Visual Studio .Net is an Integrated Development Environment (IDE), a collection of development tools exposed through a common user interface
  • 21. The .NET Framework Standards Compliance Operating System Common Language Runtime .NET Framework (Base Class Library) ADO .NET and XML ASP .NET Web Forms Web Services Mobile Internet Toolkit Windows Forms Common Language Specification C++ C# VB Perl J# … Visual Studio .NET Prog. Language Submitted to ECMA Web services – XML, SOAP-based XML-based data access Open Language Specification
  • 23. ENTITY FRAMEWORK WHAT IS? • Entity Framework was released in 2008, Microsoft's primary means of interacting between .NET applications and relational databases • It is a set of ADO.NET technologies that aid in developing data-driven software. • It is an Object Relational Mapping (ORM) framework that allows an automated way to store and access databases. The data access framework to bridge the gap between data structures and objects in the applications. • It is available as part of the .NET development (version 3.5 SP1 and later) • Microsoft’s latest and recommended way for data access for .NET applications. • It allows to develop and maintain data-oriented apps with less code than traditional applications • It eliminates the majority of the data-access code that must routinely write. • It won’t need to know about the underlying database tables and columns where data need to store
  • 25. ENTITY FRAMEWORK VERSION HISTORY ADO.NET Entity Framework Version Supported Framework & IDE Features Detail 6.0 .NET Framework 4.5.1 and Visual Studio 2013 • Async Query and Save • Code-Based Configuration • Dependency Resolution • Interception/SQL logging • Improved Connection Management • Improved Transaction Support 5.0 .NET Framework 4.5 and Visual Studio 2012 • Enum Support in Code First and EF Designer • Spatial Data Types in Code First and EF Designer • Table-Valued Functions • Multiple Diagrams per Model
  • 26. ENTITY FRAMEWORK VERSION HISTORY ADO.NET Entity Framework Version Supported Framework & IDE Features Detail 4.3 .NET Framework 4.0 and Visual Studio 2010 Code First Migrations Automatic Migrations 4.2 .NET Framework 4.0 and Visual Studio 2010 The EF 4.2 release included the bug fixes to EF 4.1 4.1 .NET Framework 4.0 and Visual Studio 2010 Code First development Introduced DbContext API Data Annotations and Fluent API Validation
  • 27. ENTITY FRAMEWORK VERSION HISTORY ADO.NET Entity Framework Version Supported Framework & IDE Features Detail 4.0 .NET Framework 4.0 and Visual Studio 2010 Model-first development POCO support Lazy Loading T4 Code Generation 3.5 .NET Framework 3.5 SP1 and Visual Studio 2008 SP1 This release provided basic O/RM support using the Database first development
  • 28. ENTITY FRAMEWORK ARCHITECTURE • EDM, Consists of Conceptual model, Mapping and Storage model. • LINQ to Entities, Used to write queries against the object model. • Entity SQL, like L2E, but little more difficult. • Object Service, Responsible for materialization. • ECDP, Responsible to convert L2E or Entity SQL queries into a SQL query. • ADO.net, Communicates with the database using standard ADO
  • 29. ENTITY FRAMEWORK ENTITY TYPES • POCO Entities (Plain Old CLR Object) POCO entities (also known as persistence-ignorant objects) support most of the same query, insert, update, and delete behaviors as entity types that are generated by the Entity Data Model. A POCO entity is a class that doesn't depend on any framework-specific base class. It is like any other normal .NET CLR class, which is why it is called "Plain Old CLR Objects". • Dynamic Proxy Entities (POCO Proxy) When creating instances of POCO entity types, the Entity Framework often creates instances of a dynamically generated derived type that acts as a proxy for the entity. IT can also be said that it is a runtime proxy classes like a wrapper class of POCO entity. Dynamic Proxy is a runtime proxy class which wraps POCO entity. Dynamic proxy entities allow lazy loading.
  • 30. ENTITY FRAMEWORK LAZY LOADING Lazy Loading is the strategy to identify resources as non- blocking (non-critical) and load them only when needed. It is the default behavior of Entity Framework, which means that the related entities or child entities are loaded only when it is being accessed for the first time. That means in simple words we can say that Lazy loading simply delays the loading of related entities until you specifically request it.
  • 31. ENTITY FRAMEWORK ENTITY PROPERTY Entities mainly consist of two types 1. Scalar Property Scalar properties are those properties that are primitive. It maps a column in a database table that stores the data. E.g., student id, student name, class are the scalar property of a student entity. 2. Navigation Property This property is responsible for the relationship of one entity to another. There are two types of navigation properties: i) Reference Navigation Property When an entity has the property of another type of entity property, it is called reference navigation property. It points to a single entity but represents the multiplicity of one. ii) Collective Navigation Property When an entity has the property of generic collection type, it is known as collective navigation property. It has the multiplicity of many.
  • 32. ENTITY FRAMEWORK ENTITY STATES • The entity framework API maintains the state of each entity during its lifetime. Each entity has a state based on the operation performed on it via the context class. The entity state represented by an enum System.Data.Entity.EntityState. • The entity framework API builds and executes the INSERT, UPDATE, and DELETE commands based on the state of an entity when the context.SaveChanges() method is called. • The Context class not only holds the reference to all the entity objects as soon as retrieved from the database, also keeps track of entity states. • The change in entity state from the Unchanged to the Modified state is the only state that's automatically handled by the context. • All other changes made explicitly by using methods of DbContext or DbSet. • Entity States • Added • Modified • Deleted • Unchanged • Detached
  • 34. ENTITY FRAMEWORK APPROACHES DATABASE FIRST Model the database artifacts (tables, views, primary keys, foreign keys, etc.) Allows you to use legacy database in your ORM application Low level control over the database Entity Data Model can be updated whenever database schema changes. Database-first approach supports stored procedure, view, etc. MODEL FIRST Creating a model using the Entity Framework designer tools Designer can generate DDL statements to create the database An easy-to-use UI allows quickly create new entities Separation of code and database in a declarative format Dropping and re-creating the database is not a choice This uses an .EDMX file to store model and mapping information. CODE FIRST The primary focus is getting the code and logic Define entity model with classes and mappings in code.. Entity Framework create (and recreate) the database for you. Does not use Entity Framework visual design tool, neither to design entities There is no XML file – no EDMX file – to represent model and storage schemas
  • 37. ENTITY FRAMEWORK FEATURES • Multiple DB Support Works with a variety both relational and non-relational servers including Microsoft SQL, MySql, Oracle, and DB2. • Cross-platform a cross-platform framework which can run on Windows, Linux and Mac • Modelling creates an EDM based on POCO (Plain Old CLR Object) entities with get/set properties of different data types. • Querying use LINQ and SQL queries to retrieve data from the underlying relational database. • Change Tracking keeps track of changes occurred to instances of entities (Property values) • Saving executes INSERT, UPDATE, and DELETE commands when call the SaveChanges() and SaveChangesAsync() method • Concurrency Optimistic Concurrency by default to protect overwriting changes made by another user • Transactions performs automatic transaction management while querying or saving data. • Caching repeated querying will return data from the cache instead of hitting the database. • Built-in Conventions follows conventions over the configuration which automatically configure the EF model. • Configurations allows us to configure the EF model by using data annotation attributes or Fluent API • Migrations commands can be executed on the NuGet Package Manager Console or CLI to create or manage underlying database Schema.
  • 38. ENTITY FRAMEWORK ADVANTAGES • Reduced development time • Developers can work more application-centric • Free from hard-coded dependencies on a particular data engine • Mappings can be change without changing the application code • L2Eprovides validation for writing queries against a conceptual model • Integrates with all the .NET application programming models • Worked well with ASP.NET, WPF, WCF, and WCF Data Services
  • 40. HOW TOs The steps involved in this example are as follows: Create the new SQL Server database Create the database objects Create a new C# Class Library Project in Visual Studio 2012 Solution Add a new ADO.NET Entity Data Model to project Create a new Database Connection Import the database objects into the EDM Modify the EDM to accommodate the scalar-valued functions
  • 48. HOW TOs The steps involved in this example are as follows: Creating the model Creating entities in the .edmx Editing entity properties Applying relationships to the entities  Name DatabaseSchema Generating the database from the model
  • 54. 16 17 18 19 20 21
  • 58. HOW TOs The steps involved in this example are as follows: Create a new Class Library Create POCO (Plain Old CLR Object) classes Add data annotations to the POCO classes. Create enum classes (if required) Add Entity Framework to the Solution Add a DbContext class Add ‘Code First Migrations’ Updates the database (if needed/made changes)
  • 61. 07
  • 64. Question & Answer “A wise man can learn more from a foolish question than a fool can learn from a wise answer.” Bruce Lee