The Entity Framework

Source: Entity Framework Code First to a New Database

So, my first glance at the Entity Framework is quite an eye-opener… For those coming from a Python background, you could essentially think that as Django is to Python, so EF is to .Net

Entity Framework

Cutting a long story short (for the long version, follow the above link and a great, to the point tutorial) EF, allows you to build your objects in your code and then creating a context (a class in which you have ‘properties’ of sets of your objects) which when running migrations and updates, creates the database and structure relevant to your code.

Of course this can’t work for every example but there are methods around this and to give you more control should you want… The one being the Fluent API which lets you override the creation (for example to define a table name instead of letting it be derived) or by using data annotations to, for example, annotate a property to be the key for the related object’s table.

There will be more to learn… For one, there are multiple scenarios to consider even at the start, such us to create the DB from code or to match the code to an already built DB… but what is possible even with just this knowledge, is rather exciting. (The source link above of course starts from scratch with code to design the object and then build the DB.)

Leave a Reply

Your email address will not be published. Required fields are marked *