Tag Archives: POCO

Customizing schema generation when using Code First with Entity Framework

In my previous post I generated a database without any mapping or customization, I got what Entity Framework could coerce from my class. Look at the schema which was generated.

generated table schema

Let’s see what I did not like about this.

  • table name is not what I like to have
  • Id was not marked as identity column, so no auto generation for this column
  • all alphanumeric columns are created using nvarchar(MAX) which is not good too
  • and the last, I wanted to use only date for birthdate not datetime

Continue reading

Using code first with Entity Framework for generating database

I was working on a personal project today, and did a lot of experiments on Code First Model with Entity Framework. All of these were quite amazing and revealed a lot of underlying implementation and how things have progressed in Entity Framework world. I looked at various articles which helped me understand all these aspects, and am grateful of all of them. So I thought why not write some posts of mine too, just to document what I have learned, so that others might benefit from it too.

For that purpose I am starting with a simplest item, I will try to generate a database for a single class, and see how it looks. By the way I am using Entity Framework 5.

Here is the class, which I will work on.

Continue reading