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

More Related Content

What's hot

ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity FrameworkDoncho 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
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
 
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
Ado.netAdo.net
Ado.net
dina1985vlr
 

What's hot (20)

ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity Framework
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
 
Entity framework 4.0
Entity framework 4.0Entity framework 4.0
Entity framework 4.0
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
Entity Framework v2 Best Practices
Entity Framework v2 Best PracticesEntity Framework v2 Best Practices
Entity Framework v2 Best Practices
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
 
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
 
Hibernate
HibernateHibernate
Hibernate
 
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)
 
Day5
Day5Day5
Day5
 
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)
 
Hibernate
HibernateHibernate
Hibernate
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
Ado .net
Ado .netAdo .net
Ado .net
 
Microsoft Database Options
Microsoft Database OptionsMicrosoft Database Options
Microsoft Database Options
 
Ado.net
Ado.netAdo.net
Ado.net
 
Ado.net
Ado.netAdo.net
Ado.net
 

Similar to Entity Framework - Entity Data Model (edm)

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 & Futureelliando dias
 
Ado.net entity framework_4.0
Ado.net entity framework_4.0Ado.net entity framework_4.0
Ado.net entity framework_4.0Rishu 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 OverviewBahaa Farouk
 
Aras PLM Roadmap
Aras PLM RoadmapAras PLM Roadmap
Aras PLM RoadmapAras
 
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 IcineticPedro 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 Daylokendralodha
 
Implicit Middleware
Implicit MiddlewareImplicit Middleware
Implicit Middleware
Till Riedel
 
.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
aminmesbahi
 
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
 
RESTful SOA and the Spring Framework (EMCWorld 2011)
RESTful SOA and the Spring Framework (EMCWorld 2011)RESTful SOA and the Spring Framework (EMCWorld 2011)
RESTful SOA and the Spring Framework (EMCWorld 2011)
EMC
 

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
 
Ado.net entity framework_4.0
Ado.net entity framework_4.0Ado.net entity framework_4.0
Ado.net entity framework_4.0
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
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
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
 
Entity framework
Entity frameworkEntity framework
Entity framework
 
Entity Framework V1 and V2
Entity Framework V1 and V2Entity Framework V1 and V2
Entity Framework V1 and V2
 
Oracle ADF Overview
Oracle ADF OverviewOracle ADF Overview
Oracle ADF Overview
 
Aras PLM Roadmap
Aras PLM RoadmapAras PLM Roadmap
Aras PLM Roadmap
 
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
 
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
 
Mahmoud Mustafa Cv
Mahmoud Mustafa CvMahmoud Mustafa Cv
Mahmoud Mustafa Cv
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
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
 
Shin J2 Ee Programming Half Day
Shin J2 Ee Programming Half DayShin J2 Ee Programming Half Day
Shin J2 Ee Programming Half Day
 
Implicit Middleware
Implicit MiddlewareImplicit Middleware
Implicit Middleware
 
.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
 
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
 
RESTful SOA and the Spring Framework (EMCWorld 2011)
RESTful SOA and the Spring Framework (EMCWorld 2011)RESTful SOA and the Spring Framework (EMCWorld 2011)
RESTful SOA and the Spring Framework (EMCWorld 2011)
 

More from Eyal Vardi

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
 

More from Eyal Vardi (20)

Why magic
Why magicWhy magic
Why magic
 
Smart Contract
Smart ContractSmart Contract
Smart Contract
 
Rachel's grandmother's recipes
Rachel's grandmother's recipesRachel's grandmother's recipes
Rachel's grandmother's recipes
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
 
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)
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
 
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
 
Angular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time CompilationAngular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time Compilation
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
 
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
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
 
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
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
 
Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 

Recently uploaded

Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 11. 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
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 20. Data Annotations © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 25. Fluent API (Types) Fluent API Samples (Click) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 28. Fluent API (Relationships) Fluent API Samples (Click) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 31. Fluent API (Properties) Fluent API Samples (Click) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 35. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 38. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 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: Eyal@E4D.co.il
  • 41. © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 42. Click here for more information © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 43. Fluent API © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il

Editor's Notes

  1. 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