Wednesday, January 1, 2014

Entity Framework - Code First

This article explains some of the features in Code First and Entity Framework in general. You can follow the tutorial series from asp.net to have some hands on experience on this.

Also checkout  this entry level tutorial

Creating Models

ID Property
When you create a model class, if you define an ID property it'll become the primary key column of the corresponding database table. Also by default the Entity Framework interprets a property that's named ID or classnameID as the primary key.

Navigation property
Navigation properties hold other entities that are related to this entity. Navigation properties are typically defined with virtual so that they can take  the advantage of lazy loading. You can put foreign key as well as the navigation property in the model class.

A property is interpreted as a foreign key if its named <navigation property name><primary key property name>

DatabaseGenerated Attribute
Specify how database generates value for a property. Let database to generate primary key. This attribute exists in System.ComponentModel namespace

You can find more code first conventions on MSDN.  

Database Initializers

see codeguru , google search ,
You can populate test data using Seed method. don't forget to update the web.config as well. 

Database Initializers in Code First
- in Web.config
- in Global.asax Application_Start

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