Wriju's BLOG

.NET, Cloud and everything

Channel 9 Video on Entity Framework 4.1

Published the video on ADO.NET Entity Framework 4.1 Code First Development video. This covers quickly the basic features if this amazing product. Check it out at https://channel9.msdn.com/posts/EF41CodeFirst The code used for the demo is using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity; using System.ComponentModel.DataAnnotations; namespace EF41CodeFirst_BDotnet { //Dept Class public class Dept {… Read more

Code First EF 4.1 : Table per Hierarchy

Concept of Table Per Hierarchy (TPH) is to implement polymorphism and to de-normalize the relational database via inheritance. The entire hierarchy is mapped to a single database table holding all the properties of all the classes. The database then would create a column called “[Discriminator]” to hold the specific type. In Code First this is… Read more

Using ADO.NET EF 4.1 Code First with existing Database

Most of the time questions comes to our mind about EF 4.1 Code First whether or not can we use it with already available database? Simple answer is YES. I have very few personal view on it. I have seen in most of my application development scenario, database gets designed and created before and then… Read more

Code First EF 4.1 : Building Many to Many Relationship

Since we do not have any designer question might arise how can we create Many to Many relationship in Code First 4.1. Here it is public class Emp { public Emp() { Projects = new HashSet<Project>(); } public int EmpId { get; set; } public string EmpName { get; set; } public ICollection<Project> Projects {… Read more

CodeFirst EF 4.1 : Changing Database Table and Column name

At times we need to control the Table and Column name of our generated database or have different Entity/Property name of code than actual database in EF 4.1 Code First. There are two ways we can do it. Using Annotations using System.ComponentModel.DataAnnotations; //Changing database Table name to Employee [Table("Employee")] public class Emp { //Changing database… Read more

Code First EF 4.1 : Missing “ADO.NET DbContext Generator” VS Template

I have seen people coming back to me asking questions about the template visible in Visual Studio 2010 as “ADO.NET DbContext Generator”. This template allows you to create the POCO classes and the context for CodeFirst from already existing edmx file. The template in Visual Studio looks like But missing. But why? At times if… Read more

Code First 4.1 : Using Stored Procedure to Insert Data

Code First in Entity Framework does not support Stored Procedure by default. As there is no designer we cannot even map our stored procs to the entity. There are a many scenario we have seen where we are bound to use stored procedure for any database modifications (insert/update/delete). Here is how we can use stored… Read more

EF 4.1 Code First Validation

When we either use the Fluent API or the attribute to put restrictions to our properties and while adding if we violet that, error would occur. Code First provides us set of classes to capture them Code First Model public class Department {     [Key]     public int DeptId { get; set; }     public… Read more

ADO.NET Entity Framework Code First 4.1 – Online

April 20, 2011 at 11 AM Pacific Time. Please register at https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&ActivityId=731858 Learn what is new in ADO.NET Entity Framework Code First 4.1 ADO.NET Entity Framework comes with a new update to make things simpler while accessing data. ·         Background – no edmx, no visual model ·         Assemblies ·         Create and Load Database ·         Data… Read more

EF Code First 4.1 Lazy Loading

EF Code First supports Lazy Loading as Model (edmx). You need to define the navigation properties to set the relationship to load the query. So if we try to implement the below code 1: public class Department 2: { 3: [Key] //To make it Primary Key and Identity 4: public int DeptId { get; set;… Read more