SlideShare a Scribd company logo
Entity Data Model (EDM)


  Eyal Vardi
  CEO E4D Solutions LTD
  Microsoft MVP Visual C#
  blog: www.eVardi.com
EF Architecture

           LINQ to Entities                                Entity SQL              EDM
                                                                                 Conceptual
                              Object Services                                      Model

                                                                                  Mapping
                         Entity Client Provider
                                                                                  Storage
                            ADO.NET Provider                                       Model




                                                        SQLServer

© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Entity Data Model (EDM)
           The EDM is the link between the model and
            the database.
           The EDM is that it decouples your application
            from the underlying store.



                          Entity Data Model (EDM)
                               Conceptual                                        Storage
                                                          Mapping
                                  Model                                           Model    Storage
                                                           (MSL)
                                 (CSDL)                                          (SSDL)




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Agenda
                                                                                 LINQ to                Entity    EDM
                                                                                 Entities                SQL

                                                                                                                 Conceptu
                                                                                      Object Services            al Model



                                                                                                                 Mapping
                                                                                   Entity Client Provider

                                                                                                                 Storage
                                                                                                                  Model
                                                                                    ADO.NET Provider




           EF Architecture

           Development Approaches

           Entity Data Model (EDM)

           Object Services

           Querying & Loading Entities




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
LINQ to                Entity    EDM
                                                                                 Entities                SQL

                                                                                                                 Conceptu
                                                                                      Object Services            al Model



                                                                                                                 Mapping
                                                                                   Entity Client Provider

                                                                                                                 Storage
                                                                                                                  Model
                                                                                    ADO.NET Provider




    Development Approaches




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Database First
           If you already have a database, the Entity
            Framework can automatically generate a data
            model that consists of classes and properties
            that correspond to existing database objects
            such as tables and columns.


                                                                                 Generated
                                                    Database First               Data Model
                   DB
                                                                                  (.edmx)



© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Model First
           If you don't yet have a database, you can
            begin by creating a model using the Entity
            Framework designer in Visual Studio.
                  The designer can generate DDL (data definition language)
                   statements to create the database.




             Data Model                                Model First               Generated
              (.edmx)
                                                                                    DB




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Code First
           Whether you have an existing database or not, you
            can code your own classes and properties that
            correspond to tables and columns and use them with
            the Entity Framework without an .edmx file.



             Data Model                                 Code First                 Generated
              (Classes)
                                                                                      DB




                                                                                 Generated
                                                        Code First               Data Model
                   DB
                                                                                  (Classes)

© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Conventions
           The pluralized forms of entity class names are
            used as table names.

           Entity property names are used for column
            names.

           Entity properties that are named ID or
            classnameID are recognized as primary key
            properties.




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
LINQ to                Entity    EDM
                                                                                 Entities                SQL

                                                                                                                 Conceptu
                                                                                      Object Services            al Model



                                                                                                                 Mapping
                                                                                   Entity Client Provider

                                                                                                                 Storage
                                                                                                                  Model
                                                                                    ADO.NET Provider




         Database Configuration




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Database Configuration(Code First)



                             DB Name                                             Connection Name
                          (no config file )




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Initialization Strategy (Code First)
           Initialize the database, the first time a context
            is used in an AppDomain.
           The following initializers are supported:
                  CreateDatabaseIfNotExist
                  DropCreateDatabaseAlways
                  DropCreateDatabaseIfModelChanges




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Seeding a Database (Code First)
           The Seed method takes whatever you put in
            the context and saves it to the database.
                  you don’t need to call SaveChanges but you DO need to be
                   sure to call the base Seed method at the end.
                  Database.SetInitializer( new DbInit() );




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Database Configuration
           Model First is different from Code First in that
            your Entity Data Model (EDM) already exists.




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
LINQ to                Entity    EDM
                                                                                 Entities                SQL

                                                                                                                 Conceptu
                                                                                      Object Services            al Model



                                                                                                                 Mapping
                                                                                   Entity Client Provider

                                                                                                                 Storage
                                                                                                                  Model
                                                                                    ADO.NET Provider




                        Data Annotations




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Data Annotations
           Code first gives you two ways to add these
            configurations to your classes.
                  Data Annotations

                  Fluent API




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Data Annotations
           Map your code first classes to a pre-existing
            database.
                  Key                                                          DatabaseGenerated
                  NotMapped                                                    InverseProperty
                  ComplexType                                                  ForeignKey
                  ConcurrencyCheck
                  TimeStamp
                  Table and Column




             MSDN link
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Validation Attribures
           Validation your code first classes.
                  Required
                  StringLength
                  MaxLength & MinLength



                       public class ProductMD
                       {
                           [StringLength(50)]
                           [Required]
                           public object Name { get; set; }

                             [Required]
                             public object Weight { get; set; }
                       }


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Validations
           DbContext automatically validates entities
            before saving them to the database.
           Validation is performed based on model facets
            as well as on data annotations. Entities can
            also be validated on demand.




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Data Annotations


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
LINQ to                Entity    EDM
                                                                                 Entities                SQL

                                                                                                                 Conceptu
                                                                                      Object Services            al Model



                                                                                                                 Mapping
                                                                                   Entity Client Provider

                                                                                                                 Storage
                                                                                                                  Model
                                                                                    ADO.NET Provider




                                        Fluent API




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Fluent API
           Specify additional mapping configuration that
            will override the default Code First
            conventions.
           Map to an existing database schema or to
            affect the shape of a generated schema.




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Fluent API (DbModelBuilder)
           Fluent API Exposed through the
            DbModelBuilder.
                  Properties with Fluent API

                  Types with Fluent API

                  Relationships with Fluent API




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Fluent API (Types)
           Specifying
                  Complex Type

                  Not to map a CLR entity type to a table in the database


           Mapping
                  a CLR entity type to a specific table in the database

                   The table-per-hierarchy (TPH) inheritance

                  The table-per-type (TPT) inheritance

                  The table-per-concrete class (TPC) inheritance

                  CLR properties of an entity type to multiple tables in the database

                  Multiple entity types to one table in the database


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Fluent API (Types)




         Fluent API Samples (Click)
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Fluent API (Relationships)
           Configuring:
                   a one-to-zero-or-one relationship
                  a relationship where both ends are required
                  a many-to-many relationship
                  a relationship with one navigation property
                  a composite foreign key
                  a foreign key name that does not follow the Code First
                   convention

           Enabling cascade delete

           Renaming a foreign key that is not defined in the
            model
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Relationships (HasXXXWithXXX)
                                  Principal                                  Dependent




                   modelBuilder.Entity<Course>()
                               .HasRequired( t => t.Department)
                               .WithMany(     t => t.Courses)
                               .HasForeignKey(d => d.DepartmentID)
                               .WillCascadeOnDelete(false);


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Fluent API (Relationships)




   Fluent API Samples (Click)
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Cascade Delete
           You can configure cascade delete on a
            relationship by using the
            WillCascadeOnDelete method.
           You can remove these cascade delete
            conventions by using:
                  modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>()
                  modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>()




                   modelBuilder.Entity<Course>()
                               .HasRequired( t => t.Department)
                               .WithMany(     t => t.Courses)
                               .HasForeignKey(d => d.DepartmentID)
                               .WillCascadeOnDelete(false);


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Fluent API (Properties)
           Primary & Foreign key

           Maximum length

           Required

           Mapping a CLR property to a specific column in the database

           Unicode content

           Data type of a database column

           Complex type

           Optimistic concurrency token



© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Fluent API
   (Properties)




         Fluent API Samples (Click)
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
LINQ to                Entity    EDM
                                                                                 Entities                SQL

                                                                                                                 Conceptu
                                                                                      Object Services            al Model



                                                                                                                 Mapping
                                                                                   Entity Client Provider

                                                                                                                 Storage
                                                                                                                  Model
                                                                                    ADO.NET Provider




                Inheritance Mapping




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Inheritance Mapping
           Inheritance mapping strategies:
                  Table per Hierarchy (TPH)

                  Table per Type (TPT)

                  Table per Concrete Type (TPC)




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Table per Hierarchy (TPH)
           An entire class hierarchy can be mapped
            to a single table.
                  This table includes columns for all properties of
                   all classes in the hierarchy.




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
TPH with Fluent API
           The code will change the discriminator column name
            to "BillingDetailType" and the values to "BA" and
            "CC" for BankAccount and CreditCard respectively:




         Click here for more information
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Table per Type (TPT)
           TPT is about representing inheritance relationships as
            relational foreign key associations.
                 Every class/subclass that declares persistent properties—
                  including abstract classes—has its own table.




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
TPT with Fluent API
           TPT mapping by using ToTable() method.




         Click here for more information
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Table per Concrete Type (TPC)
           In TPC type we use exactly one table for each
            (nonabstract) class.




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Click here for more information
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Fluent API


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Ad

More Related Content

What's hot (20)

ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
Doncho Minkov
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity Framework
LearnNowOnline
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
James Johnson
 
Entity framework 4.0
Entity framework 4.0Entity framework 4.0
Entity framework 4.0
Abhishek Sur
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
ukdpe
 
Entity Framework v2 Best Practices
Entity Framework v2 Best PracticesEntity Framework v2 Best Practices
Entity Framework v2 Best Practices
Andri Yadi
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
Stefano Paluello
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
Mahmoud Tolba
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
Virtual Nuggets
 
LINQ to Relational in Visual Studio 2008 SP1
LINQ to Relational in Visual Studio 2008 SP1LINQ to Relational in Visual Studio 2008 SP1
LINQ to Relational in Visual Studio 2008 SP1
ukdpe
 
Hibernate
HibernateHibernate
Hibernate
Murali Pachiyappan
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Day5
Day5Day5
Day5
madamewoolf
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Hibernate
HibernateHibernate
Hibernate
Ajay K
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
Raveendra R
 
Ado .net
Ado .netAdo .net
Ado .net
Manish Singh
 
Microsoft Database Options
Microsoft Database OptionsMicrosoft Database Options
Microsoft Database Options
David Chou
 
Ado.net
Ado.netAdo.net
Ado.net
Sangeetha Rangarajan
 
Ado.net
Ado.netAdo.net
Ado.net
dina1985vlr
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
Doncho Minkov
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity Framework
LearnNowOnline
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
James Johnson
 
Entity framework 4.0
Entity framework 4.0Entity framework 4.0
Entity framework 4.0
Abhishek Sur
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
ukdpe
 
Entity Framework v2 Best Practices
Entity Framework v2 Best PracticesEntity Framework v2 Best Practices
Entity Framework v2 Best Practices
Andri Yadi
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
Mahmoud Tolba
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
Virtual Nuggets
 
LINQ to Relational in Visual Studio 2008 SP1
LINQ to Relational in Visual Studio 2008 SP1LINQ to Relational in Visual Studio 2008 SP1
LINQ to Relational in Visual Studio 2008 SP1
ukdpe
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Hibernate
HibernateHibernate
Hibernate
Ajay K
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
Raveendra R
 
Microsoft Database Options
Microsoft Database OptionsMicrosoft Database Options
Microsoft Database Options
David Chou
 

Similar to Entity Framework - Entity Data Model (edm) (20)

Model Driven Architecture (MDA): Motivations, Status & Future
Model Driven Architecture (MDA): Motivations, Status & FutureModel Driven Architecture (MDA): Motivations, Status & Future
Model Driven Architecture (MDA): Motivations, Status & Future
elliando dias
 
Ado.net entity framework_4.0
Ado.net entity framework_4.0Ado.net entity framework_4.0
Ado.net entity framework_4.0
Rishu Mehra
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2
Eric Nelson
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
Hasnain Iqbal
 
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
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
Eric Nelson
 
Entity framework
Entity frameworkEntity framework
Entity framework
Tamer Elshahat
 
Entity Framework V1 and V2
Entity Framework V1 and V2Entity Framework V1 and V2
Entity Framework V1 and V2
ukdpe
 
Oracle ADF Overview
Oracle ADF OverviewOracle ADF Overview
Oracle ADF Overview
Bahaa Farouk
 
Aras PLM Roadmap
Aras PLM RoadmapAras PLM Roadmap
Aras PLM Roadmap
Aras
 
Modelling and code generation in .NET at Icinetic
Modelling and code generation in .NET at IcineticModelling and code generation in .NET at Icinetic
Modelling and code generation in .NET at Icinetic
Pedro J. Molina
 
Modelling and code generation in .NET at Icinetic
Modelling and code generation in .NET at IcineticModelling and code generation in .NET at Icinetic
Modelling and code generation in .NET at Icinetic
Icinetic
 
Mahmoud Mustafa Cv
Mahmoud Mustafa CvMahmoud Mustafa Cv
Mahmoud Mustafa Cv
Mahmoud Mustafa
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
Knoldus Inc.
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Enea Gabriel
 
Shin J2 Ee Programming Half Day
Shin J2 Ee Programming Half DayShin J2 Ee Programming Half Day
Shin J2 Ee Programming Half Day
lokendralodha
 
Implicit Middleware
Implicit MiddlewareImplicit Middleware
Implicit Middleware
Till Riedel
 
Entity Framework Interview Questions PDF By ScholarHat
Entity Framework Interview Questions PDF By ScholarHatEntity Framework Interview Questions PDF By ScholarHat
Entity Framework Interview Questions PDF By ScholarHat
Scholarhat
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13
Amin Mesbahi
 
Compositional AI: Fusion of AI/ML Services
Compositional AI: Fusion of AI/ML ServicesCompositional AI: Fusion of AI/ML Services
Compositional AI: Fusion of AI/ML Services
Debmalya Biswas
 
Model Driven Architecture (MDA): Motivations, Status & Future
Model Driven Architecture (MDA): Motivations, Status & FutureModel Driven Architecture (MDA): Motivations, Status & Future
Model Driven Architecture (MDA): Motivations, Status & Future
elliando dias
 
Ado.net entity framework_4.0
Ado.net entity framework_4.0Ado.net entity framework_4.0
Ado.net entity framework_4.0
Rishu Mehra
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2
Eric Nelson
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
Hasnain Iqbal
 
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
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
Eric Nelson
 
Entity Framework V1 and V2
Entity Framework V1 and V2Entity Framework V1 and V2
Entity Framework V1 and V2
ukdpe
 
Oracle ADF Overview
Oracle ADF OverviewOracle ADF Overview
Oracle ADF Overview
Bahaa Farouk
 
Aras PLM Roadmap
Aras PLM RoadmapAras PLM Roadmap
Aras PLM Roadmap
Aras
 
Modelling and code generation in .NET at Icinetic
Modelling and code generation in .NET at IcineticModelling and code generation in .NET at Icinetic
Modelling and code generation in .NET at Icinetic
Pedro J. Molina
 
Modelling and code generation in .NET at Icinetic
Modelling and code generation in .NET at IcineticModelling and code generation in .NET at Icinetic
Modelling and code generation in .NET at Icinetic
Icinetic
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
Knoldus Inc.
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Enea Gabriel
 
Shin J2 Ee Programming Half Day
Shin J2 Ee Programming Half DayShin J2 Ee Programming Half Day
Shin J2 Ee Programming Half Day
lokendralodha
 
Implicit Middleware
Implicit MiddlewareImplicit Middleware
Implicit Middleware
Till Riedel
 
Entity Framework Interview Questions PDF By ScholarHat
Entity Framework Interview Questions PDF By ScholarHatEntity Framework Interview Questions PDF By ScholarHat
Entity Framework Interview Questions PDF By ScholarHat
Scholarhat
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13
Amin Mesbahi
 
Compositional AI: Fusion of AI/ML Services
Compositional AI: Fusion of AI/ML ServicesCompositional AI: Fusion of AI/ML Services
Compositional AI: Fusion of AI/ML Services
Debmalya Biswas
 
Ad

More from Eyal Vardi (20)

Why magic
Why magicWhy magic
Why magic
Eyal Vardi
 
Smart Contract
Smart ContractSmart Contract
Smart Contract
Eyal Vardi
 
Rachel's grandmother's recipes
Rachel's grandmother's recipesRachel's grandmother's recipes
Rachel's grandmother's recipes
Eyal Vardi
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
Eyal Vardi
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
Eyal Vardi
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
Angular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time CompilationAngular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time Compilation
Eyal Vardi
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
Eyal Vardi
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
Eyal Vardi
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
Eyal Vardi
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
Eyal Vardi
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
Eyal Vardi
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
Eyal Vardi
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
Eyal Vardi
 
Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
Eyal Vardi
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
Smart Contract
Smart ContractSmart Contract
Smart Contract
Eyal Vardi
 
Rachel's grandmother's recipes
Rachel's grandmother's recipesRachel's grandmother's recipes
Rachel's grandmother's recipes
Eyal Vardi
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
Eyal Vardi
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
Eyal Vardi
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
Angular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time CompilationAngular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time Compilation
Eyal Vardi
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
Eyal Vardi
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
Eyal Vardi
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
Eyal Vardi
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
Eyal Vardi
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
Eyal Vardi
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
Eyal Vardi
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
Eyal Vardi
 
Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
Eyal Vardi
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
Ad

Recently uploaded (20)

Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 

Entity Framework - Entity Data Model (edm)

  • 1. Entity Data Model (EDM) Eyal Vardi CEO E4D Solutions LTD Microsoft MVP Visual C# blog: www.eVardi.com
  • 2. EF Architecture LINQ to Entities Entity SQL EDM Conceptual Object Services Model Mapping Entity Client Provider Storage ADO.NET Provider Model SQLServer © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 3. Entity Data Model (EDM)  The EDM is the link between the model and the database.  The EDM is that it decouples your application from the underlying store. Entity Data Model (EDM) Conceptual Storage Mapping Model Model Storage (MSL) (CSDL) (SSDL) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 4. Agenda LINQ to Entity EDM Entities SQL Conceptu Object Services al Model Mapping Entity Client Provider Storage Model ADO.NET Provider  EF Architecture  Development Approaches  Entity Data Model (EDM)  Object Services  Querying & Loading Entities © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 5. LINQ to Entity EDM Entities SQL Conceptu Object Services al Model Mapping Entity Client Provider Storage Model ADO.NET Provider Development Approaches © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 6. Database First  If you already have a database, the Entity Framework can automatically generate a data model that consists of classes and properties that correspond to existing database objects such as tables and columns. Generated Database First Data Model DB (.edmx) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 7. Model First  If you don't yet have a database, you can begin by creating a model using the Entity Framework designer in Visual Studio.  The designer can generate DDL (data definition language) statements to create the database. Data Model Model First Generated (.edmx) DB © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 8. Code First  Whether you have an existing database or not, you can code your own classes and properties that correspond to tables and columns and use them with the Entity Framework without an .edmx file. Data Model Code First Generated (Classes) DB Generated Code First Data Model DB (Classes) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 9. Conventions  The pluralized forms of entity class names are used as table names.  Entity property names are used for column names.  Entity properties that are named ID or classnameID are recognized as primary key properties. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 10. LINQ to Entity EDM Entities SQL Conceptu Object Services al Model Mapping Entity Client Provider Storage Model ADO.NET Provider Database Configuration © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 11. Database Configuration(Code First) DB Name Connection Name (no config file ) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 12. Initialization Strategy (Code First)  Initialize the database, the first time a context is used in an AppDomain.  The following initializers are supported:  CreateDatabaseIfNotExist  DropCreateDatabaseAlways  DropCreateDatabaseIfModelChanges © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 13. Seeding a Database (Code First)  The Seed method takes whatever you put in the context and saves it to the database.  you don’t need to call SaveChanges but you DO need to be sure to call the base Seed method at the end.  Database.SetInitializer( new DbInit() ); © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 14. Database Configuration  Model First is different from Code First in that your Entity Data Model (EDM) already exists. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 15. LINQ to Entity EDM Entities SQL Conceptu Object Services al Model Mapping Entity Client Provider Storage Model ADO.NET Provider Data Annotations © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 16. Data Annotations  Code first gives you two ways to add these configurations to your classes.  Data Annotations  Fluent API © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 17. Data Annotations  Map your code first classes to a pre-existing database.  Key  DatabaseGenerated  NotMapped  InverseProperty  ComplexType  ForeignKey  ConcurrencyCheck  TimeStamp  Table and Column MSDN link © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 18. Validation Attribures  Validation your code first classes.  Required  StringLength  MaxLength & MinLength public class ProductMD { [StringLength(50)] [Required] public object Name { get; set; } [Required] public object Weight { get; set; } } © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 19. Validations  DbContext automatically validates entities before saving them to the database.  Validation is performed based on model facets as well as on data annotations. Entities can also be validated on demand. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 20. Data Annotations © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 21. LINQ to Entity EDM Entities SQL Conceptu Object Services al Model Mapping Entity Client Provider Storage Model ADO.NET Provider Fluent API © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 22. Fluent API  Specify additional mapping configuration that will override the default Code First conventions.  Map to an existing database schema or to affect the shape of a generated schema. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 23. Fluent API (DbModelBuilder)  Fluent API Exposed through the DbModelBuilder.  Properties with Fluent API  Types with Fluent API  Relationships with Fluent API © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 24. Fluent API (Types)  Specifying  Complex Type  Not to map a CLR entity type to a table in the database  Mapping  a CLR entity type to a specific table in the database  The table-per-hierarchy (TPH) inheritance  The table-per-type (TPT) inheritance  The table-per-concrete class (TPC) inheritance  CLR properties of an entity type to multiple tables in the database  Multiple entity types to one table in the database © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 25. Fluent API (Types) Fluent API Samples (Click) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 26. Fluent API (Relationships)  Configuring:  a one-to-zero-or-one relationship  a relationship where both ends are required  a many-to-many relationship  a relationship with one navigation property  a composite foreign key  a foreign key name that does not follow the Code First convention  Enabling cascade delete  Renaming a foreign key that is not defined in the model © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 27. Relationships (HasXXXWithXXX) Principal Dependent modelBuilder.Entity<Course>() .HasRequired( t => t.Department) .WithMany( t => t.Courses) .HasForeignKey(d => d.DepartmentID) .WillCascadeOnDelete(false); © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 28. Fluent API (Relationships) Fluent API Samples (Click) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 29. Cascade Delete  You can configure cascade delete on a relationship by using the WillCascadeOnDelete method.  You can remove these cascade delete conventions by using:  modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>()  modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>() modelBuilder.Entity<Course>() .HasRequired( t => t.Department) .WithMany( t => t.Courses) .HasForeignKey(d => d.DepartmentID) .WillCascadeOnDelete(false); © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 30. Fluent API (Properties)  Primary & Foreign key  Maximum length  Required  Mapping a CLR property to a specific column in the database  Unicode content  Data type of a database column  Complex type  Optimistic concurrency token © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 31. Fluent API (Properties) Fluent API Samples (Click) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 32. LINQ to Entity EDM Entities SQL Conceptu Object Services al Model Mapping Entity Client Provider Storage Model ADO.NET Provider Inheritance Mapping © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 33. Inheritance Mapping  Inheritance mapping strategies:  Table per Hierarchy (TPH)  Table per Type (TPT)  Table per Concrete Type (TPC) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 34. Table per Hierarchy (TPH)  An entire class hierarchy can be mapped to a single table.  This table includes columns for all properties of all classes in the hierarchy. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 35. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 36. TPH with Fluent API  The code will change the discriminator column name to "BillingDetailType" and the values to "BA" and "CC" for BankAccount and CreditCard respectively: Click here for more information © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 37. Table per Type (TPT)  TPT is about representing inheritance relationships as relational foreign key associations.  Every class/subclass that declares persistent properties— including abstract classes—has its own table. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 38. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 39. TPT with Fluent API  TPT mapping by using ToTable() method. Click here for more information © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 40. Table per Concrete Type (TPC)  In TPC type we use exactly one table for each (nonabstract) class. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 41. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 42. Click here for more information © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 43. Fluent API © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]

Editor's Notes

  • #35: Create the table in the DBAdd the mapping for Person and subclass Customer. &lt;discriminator&gt;PersonType&lt;/&gt; in the Person classdiscriminator-value=“Customer” in the subclassRefactorDataProvider to load, save and delete all kind of types