Mapping single class with a table was bit easy and fun. Next should be mapping associations, first I will try to map a simple one, using our existing application code. A person can have multiple email addresses.
So here is the modified code for person
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.
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
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.