Wednesday, November 13, 2013

Other resources for Entity Framework


Difference between Eager loading and Lazy loading


http://stackoverflow.com/questions/3485317/entity-framework-4-single-vs-first-vs-firstordefault


Bulk Inserting in Entity Framework
http://stackoverflow.com/questions/5940225/fastest-way-of-inserting-in-entity-framework
http://stackoverflow.com/questions/6107206/improving-bulk-insert-performance-in-entity-framework

...............

  • By default, EF interprets a property that's named ID or classnameID as the primary key
    • using ID without classname makes it easier to implement inheritance in the data model
  • Navigation properties are typically defined as virtual so they can take advantage of certain EF functionality such as lazy loading. 
  • DatabaseGenerated is an attribute you can define on primary key. It says you'll manually enter the primary key rather than Database generating it.
  • The main class that coordinates EF functionality for a given data model is the database context class.
    • You create this class by deriving from System.Data.Entity.DbContext class
    • In your code you specify which entities are included in the data model

    • This code creates a DbSet property for each entity set. In EF, an entity set typically corresponds to a database table, and an entity corresponds to a row in the table.
    • Above, SchoolContext is the name of the connection string you define in Web.config
      • You can also pass the connection string itself (link)
      • If you don't pass anything to base, EF assumes the connection string name is the same as the class name
    • You can write a Seed method for EF to generate data


Useful methods

ObjectContext.SaveChanges()

Persists all updates to the data source and resets change tracking in the object context. Returns no. of objects in an added, modifled or deleted state when SaveChanges was called

link1, link2, link3


Configuring Entity Framework
You can configure entity framework options from the config file. Starting from EF 6 you can use Code based configurations.

sources

0 comments:

Post a Comment

Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook