Feb 12, 2010

Get started with EntityFramework 4

We have the following option to using EntityFramework4

  • Using designer
    • Model First

      We can design model first , then generate the sql for the model, use the sql to generate the database, and then connect the model to the database. The process of sql gereration is customizable. You change this workflow (process) and the template of the sql, these file are located at C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen.
      ASO.NET team blog has an article about this a approach.

    • Database First

      This is a classic approach. You have your database in the first place, and generate model based on that.

    Since you have use the designer, you have other customization options that are related to code generation from the model created by designer. But default designer use a Code generation strategy call "Default". If you model file name is "model.edmx", the strategy generate a cs file "model.cs" file, and the code generate the ObjectContext, and other entities, and so forth. The entities

    [EdmEntityTypeAttribute(NamespaceName="CrmModel", Name="Post")]
    public partial class Post : EntityObject
    { ... }

    Since EF4 use t4 to generate code, you can customized the t4 to customized the code generation by right clicking the designer and adding code generation item. When you add code generation item, this will turn off the default code generation strategy. Your model.cs file will be empty.

    There are a couple code generation item available now. When you add an item a t4 file (*.tt) is added to the project. You can customize the tt file as want.

  • Use code only
    Feature CTP Walkthrough: Code Only for the Entity Framework (Updated)

No comments:

Post a Comment