Save yourself some trouble :
http://visualstudiogallery.msdn.microsoft.com/ee4fcff9-0c4c-4179-afd9-7a2fb90f5838
EntityFramework Reverse POCO Generator
OR
http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d
Entity Framework Power Tools Beta 4
Reverse Engineer Code First - Generates POCO classes, derived DbContext and Code First mapping for an existing database.
===========================================
Run it before you leave for the evening..and check your screen saver settings. (Aka, it could take a while, esp the "Power Tools" one.
===========================================
Here is a Northwind "Customer" example. Perhaps you can map it to your table.
namespace NorthWindyDataLayer.Models
{
[Serializable]
public partial class Customer
{
public Customer()
{
}
public string CustomerID { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
}
}
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
namespace NorthWindyDataLayer.Models
{
public partial class WindyContext : DbContext
{
static WindyContext()
{
//Database.SetInitializer<WindyContext>(null);
}
public WindyContext()
: base("Name=NorthwindContext")
{
}
public DbSet<Customer> Customers { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new CustomerMap());
}
}
}
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
namespace NorthWindyDataLayer.Models.Mapping
{
public class CustomerMap : EntityTypeConfiguration<Customer>
{
public CustomerMap()
{
// Primary Key
this.HasKey(t => t.CustomerID);
// Properties
this.Property(t => t.CustomerID)
.IsRequired()
.IsFixedLength()
.HasMaxLength(5);
this.Property(t => t.CompanyName)
.IsRequired()
.HasMaxLength(40);
this.Property(t => t.ContactName)
.HasMaxLength(30);
this.Property(t => t.ContactTitle)
.HasMaxLength(30);
this.Property(t => t.Address)
.HasMaxLength(60);
this.Property(t => t.City)
.HasMaxLength(15);
this.Property(t => t.Region)
.HasMaxLength(15);
this.Property(t => t.PostalCode)
.HasMaxLength(10);
this.Property(t => t.Country)
.HasMaxLength(15);
this.Property(t => t.Phone)
.HasMaxLength(24);
this.Property(t => t.Fax)
.HasMaxLength(24);
// Table & Column Mappings
this.ToTable("Customers");
this.Property(t => t.CustomerID).HasColumnName("CustomerID");
this.Property(t => t.CompanyName).HasColumnName("CompanyName");
this.Property(t => t.ContactName).HasColumnName("ContactName");
this.Property(t => t.ContactTitle).HasColumnName("ContactTitle");
this.Property(t => t.Address).HasColumnName("Address");
this.Property(t => t.City).HasColumnName("City");
this.Property(t => t.Region).HasColumnName("Region");
this.Property(t => t.PostalCode).HasColumnName("PostalCode");
this.Property(t => t.Country).HasColumnName("Country");
this.Property(t => t.Phone).HasColumnName("Phone");
this.Property(t => t.Fax).HasColumnName("Fax");
}
}
}