SlideShare a Scribd company logo
EF Code First Model Key Idea How it works? Database Initialize Data Annotation Dmytryi  Lebedinskyi
Code First Model 1. Define Simple Entities with connection by ID
2.  Add virtual properties for lazy loading of Aggregated Fields EF lazy loading is enabled by default Code First Model
3.  Remember to preserve name convention  EF Code First uses general agreement about names.  Code First Model
4.  Create Data Context DbContext is similar to EF general Data Context Code First Model
Code First Model 5.  Create a Repositories
6.  What about usage?  You can work with it same like a general EF Model Code First Model
7. And what is the result? Code First Model
Code First Model 9.  Where is Database?  Default  DB Server is .\SqlExpress
Code First Model 10.  Change Database name  How to change DB name? App.config or any other Connection String supplied  DbConnection  Replace the Default Convention  
EF Code First Model Key Idea How it works? Database Initialize Data Annotations
Code First Model Database Initializers System.Data.Entity.Database .IDatabaseInitializer <in TContext> CreateDatabaseIfNotExists DropCreateDatabaseIfModelChanges DropCreateDatabaseAlways
Code First Model 1. Create  Initializer
Code First Model 2 .  Register Initializer
Code First Model 3 .  And we have data if no db is created
EF Code First Model Key Idea How it works? Database Initialize Data Annotations
Since EF Code First  CTP5 Data Annotations can be used for DB structure Code First Model KeyAttribute StringLengthAttribute MaxLengthAttribute ConcurrencyCheckAttribute RequiredAttribute TimestampAttribute ComplexTypeAttribute ColumnAttribute   (Placed on a property to specify the column name, ordinal & data type) TableAttribute   (Placed on a class to specify the table name and schema) InversePropertyAttribute  ( Placed on a navigation property to specify the property that represents the other end of a relationship) ForeignKeyAttribute  (Placed on a navigation property to specify the property that represents the foreign key of the relationship) DatabaseGeneratedAttribute  ( Placed on a property to specify how the database generates a value for the property (Identity, Computed or None) ) NotMappedAttribute  ( Placed on a property or class to exclude it from the database)
And Validation Attributes are now also supported Code First Model
And using  some MVC Magic we receive  Code First Model
Questions? :)

More Related Content

PPTX
Mca ii dfs u-2 array records and pointer
PPT
uptu web technology unit 2 Xml2
PPT
uptu web technology unit 2 Xml2
PPTX
Object oriented database concepts
PPTX
Object oriented database
PPSX
Data Structures by Yaman Singhania
Mca ii dfs u-2 array records and pointer
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
Object oriented database concepts
Object oriented database
Data Structures by Yaman Singhania

What's hot (20)

PPT
uptu web technology unit 2 Xml2
PPTX
PPTX
Typedef
PPTX
Clean code
PPTX
Intro to python
PPTX
Entity Framework
PDF
Object oriented databases
PPTX
Jason yousef ssis expressions - no notes
DOCX
Declaration programming 2017
PPTX
PPTX
Flyweight Pattern
DOCX
Structure and Typedef
DOCX
Dot net programming concept
PPT
Xml Presentation-1
PPTX
Xml dtd
PDF
Kotlin generics
PPTX
Data Types - Premetive and Non Premetive
PPTX
Datastrucure
uptu web technology unit 2 Xml2
Typedef
Clean code
Intro to python
Entity Framework
Object oriented databases
Jason yousef ssis expressions - no notes
Declaration programming 2017
Flyweight Pattern
Structure and Typedef
Dot net programming concept
Xml Presentation-1
Xml dtd
Kotlin generics
Data Types - Premetive and Non Premetive
Datastrucure
Ad

Viewers also liked (6)

PPSX
Photo album of Chinmay &amp; Prachi
PPTX
Css 3 overview
PPTX
PDF
Dadhikar fort
PDF
Open state concept
PPT
Sonar quality
Photo album of Chinmay &amp; Prachi
Css 3 overview
Dadhikar fort
Open state concept
Sonar quality
Ad

Similar to Ef code first (20)

PDF
Intake 38 data access 5
PPTX
Ef code first
PDF
Intake 37 ef2
PPTX
Entity Frame Work Core.pptx
PPTX
02 beginning code first
PPTX
02 beginning code first
PPTX
Entity framework
PPTX
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
PPTX
Entity Framework: Code First and Magic Unicorns
PPTX
Getting started with entity framework
PPTX
Entity Framework: Nakov @ BFU Hackhaton 2015
PDF
Learn Entity Framework in a day with Code First, Model First and Database First
PPTX
Overview of entity framework by software outsourcing company india
PPTX
Entity framework code first
PDF
How to create fast and much more efficient database
PPT
Entity frameworks101
PPTX
Applying EF Code First at Your Job
PDF
An Overview of Entity Framework
PPT
Free video lectures for mca
PDF
Entity Framework Interview Questions PDF By ScholarHat
Intake 38 data access 5
Ef code first
Intake 37 ef2
Entity Frame Work Core.pptx
02 beginning code first
02 beginning code first
Entity framework
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
Entity Framework: Code First and Magic Unicorns
Getting started with entity framework
Entity Framework: Nakov @ BFU Hackhaton 2015
Learn Entity Framework in a day with Code First, Model First and Database First
Overview of entity framework by software outsourcing company india
Entity framework code first
How to create fast and much more efficient database
Entity frameworks101
Applying EF Code First at Your Job
An Overview of Entity Framework
Free video lectures for mca
Entity Framework Interview Questions PDF By ScholarHat

More from dotNETUserGroupDnipro (8)

PPTX
Mercurial presentation
PPTX
PPTX
PPTX
Soft serve prism
PPT
Erp microsoft dynamics
PPTX
Azure for ug
Mercurial presentation
Soft serve prism
Erp microsoft dynamics
Azure for ug

Ef code first

  • 1. EF Code First Model Key Idea How it works? Database Initialize Data Annotation Dmytryi Lebedinskyi
  • 2. Code First Model 1. Define Simple Entities with connection by ID
  • 3. 2. Add virtual properties for lazy loading of Aggregated Fields EF lazy loading is enabled by default Code First Model
  • 4. 3. Remember to preserve name convention EF Code First uses general agreement about names. Code First Model
  • 5. 4. Create Data Context DbContext is similar to EF general Data Context Code First Model
  • 6. Code First Model 5. Create a Repositories
  • 7. 6. What about usage? You can work with it same like a general EF Model Code First Model
  • 8. 7. And what is the result? Code First Model
  • 9. Code First Model 9. Where is Database? Default DB Server is .\SqlExpress
  • 10. Code First Model 10. Change Database name How to change DB name? App.config or any other Connection String supplied  DbConnection  Replace the Default Convention  
  • 11. EF Code First Model Key Idea How it works? Database Initialize Data Annotations
  • 12. Code First Model Database Initializers System.Data.Entity.Database .IDatabaseInitializer <in TContext> CreateDatabaseIfNotExists DropCreateDatabaseIfModelChanges DropCreateDatabaseAlways
  • 13. Code First Model 1. Create Initializer
  • 14. Code First Model 2 . Register Initializer
  • 15. Code First Model 3 . And we have data if no db is created
  • 16. EF Code First Model Key Idea How it works? Database Initialize Data Annotations
  • 17. Since EF Code First CTP5 Data Annotations can be used for DB structure Code First Model KeyAttribute StringLengthAttribute MaxLengthAttribute ConcurrencyCheckAttribute RequiredAttribute TimestampAttribute ComplexTypeAttribute ColumnAttribute   (Placed on a property to specify the column name, ordinal & data type) TableAttribute   (Placed on a class to specify the table name and schema) InversePropertyAttribute  ( Placed on a navigation property to specify the property that represents the other end of a relationship) ForeignKeyAttribute  (Placed on a navigation property to specify the property that represents the foreign key of the relationship) DatabaseGeneratedAttribute  ( Placed on a property to specify how the database generates a value for the property (Identity, Computed or None) ) NotMappedAttribute  ( Placed on a property or class to exclude it from the database)
  • 18. And Validation Attributes are now also supported Code First Model
  • 19. And using some MVC Magic we receive Code First Model