Your SlideShare is downloading. ×
Ef code first
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Ef code first

1,788
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,788
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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
  • 20. Questions? :)