This presantaion is all about ORM and how to implement the idea of ORM using C# created by Imal hasaranga perera for the microsoft monthly meeting november (sri lanka)
1. ORM in C#
Using Visual Paradigm
By : Imal Hasaranga Perera
2. Agenda
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
3. What is ORM ???
Object Relational Mapping, A way of getting object-oriented
languages and relational databases to work together
Object world Relational world
User
Stu Mapping
A…
B..
4. The Object-Relational Impedance
Mismatch
'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
6. 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{
}
7. 2. Inheritance
Inheritance is a natural paradigm in object-oriented
programming languages. However, RDBMSs do not define
anything similar to Inheritance
User_main
Inheritance
Student Teacher
8. 3. Identity
A RDBMS defines exactly one notion of 'sameness'
Teacher_id = 2233
Thread 1 Teacher
Thread 2 Teacher
9. 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 twice
Class user_main {
Teacher teacher;
}
Class Teacher {
}
10. 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
11. Reason for using ORM??
Speeds-up Development - eliminates the need for repetitive
SQL code.
Reduces Development Time.
Reduces Development Costs. User nuser = UserFactory.createUser();
Overcomes vendor specific SQL differences - the ORM
nuser.Fname = t1.Text;
knows how to write vendor specific SQLt2.Text; don't have
nuser.Lname =
so you
nuser.Type = t3.Text;
to. nuser.Save();
Rich query capability. ORM tools provide an object oriented
t.commit();
query language.