Orm in c#
-
Upload
imal-hasaranga -
Category
Education
-
view
4.209 -
download
0
description
Transcript of Orm in c#
![Page 1: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/1.jpg)
ORM in C#Using Visual Paradigm
By : Imal Hasaranga Perera
![Page 2: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/2.jpg)
What is ORM? Introduction to VP Using VP to Generate RDB Generating C# .NET Persistent Library Demo of how to use Persistent library Q & A
Agenda
![Page 3: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/3.jpg)
What is ORM ???
Object Relational Mapping, A way of getting object-oriented languages and relational databases to work together Relational
world
Stu
User
B..A…
Object world
Mapping
![Page 4: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/4.jpg)
'Object-Relational Impedance Mismatch' is just
a fancy way of saying that object models and
relational models do not work very well together.
RDBMSs represent data in a tabular format ,
whereas object-oriented languages, such as Java,
C# represent it as an interconnected graph of
objects. Loading and storing graphs of objects
using a tabular relational database exposes us to 5
mismatch problems
The Object-Relational Impedance Mismatch
![Page 5: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/5.jpg)
1) Granularity
2) Inheritance
3) Identity
4) Associations
5) Data Types
The Object-Relational Impedance Mismatch
![Page 6: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/6.jpg)
1. Granularity
Sometimes you will have an object model which has more classes than the number of corresponding tables in the database
public class Teacher{
}
public class School{
}
![Page 7: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/7.jpg)
2. Inheritance
Inheritance is a natural paradigm in object-oriented programming languages. However, RDBMSs do not define anything similar to Inheritance
User_main
Student Teacher
Inheritance
![Page 8: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/8.jpg)
3. Identity
A RDBMS defines exactly one notion of 'sameness'
Teacher_id = 2233
Thread 1
Thread 2
Teacher
Teacher
![Page 9: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/9.jpg)
4. Associations
Associations are represented as unidirectional references in Object Oriented languages whereas RDBMSs use the notion of foreign keys. If you need bidirectional relationships in C#, you must define the association twiceClass user_main {
Teacher teacher;
}
Class Teacher {
}
![Page 10: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/10.jpg)
5. Data Types
When we consider about data types there a mismatches, simply String might have limited size than a varchar data type
String Varchar(150)
Mismatches Between Date and time in the object world and the relational world
![Page 11: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/11.jpg)
Reason for using ORM??
Speeds-up Development - eliminates the need for repetitive SQL code.
Reduces Development Time. Reduces Development Costs. Overcomes vendor specific SQL differences - the
ORM knows how to write vendor specific SQL so you don't have to.
Rich query capability. ORM tools provide an object oriented query language.
User nuser = UserFactory.createUser();
nuser.Fname = t1.Text;nuser.Lname = t2.Text;nuser.Type = t3.Text;nuser.Save();
t.commit();
![Page 12: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/12.jpg)
Lets Get Started With Visual Paradigm
![Page 13: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/13.jpg)
Relational database
Example ER Diagram Created by Using VP
![Page 14: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/14.jpg)
Code Generating Process in VP
Generate C# project using Visual paradigm
![Page 15: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/15.jpg)
Q & A
![Page 16: Orm in c#](https://reader034.fdocuments.net/reader034/viewer/2022052505/5560c71cd8b42a19088b474f/html5/thumbnails/16.jpg)
Thank You