iT邦幫忙

0

Learn Entity Framework#1 | Getting Started

What is Entity Framework

Before the Entity Framework, developers often used to write ADO.Net code or Data Access Block to save or retrieve data from database. But it was time consuming and may cause lots of problems.

The Entity Framework is a persistence framework allows you to avoid doing dirty work like:

  • Stored Procedures
  • Manage Database Connections
  • Manual Mapping

The Entity Framework (EF) enables developers to work with data using objects of domain specific classes without focusing on the database tables. With EF, developers can work at a high level od abstraction and can create and maintain data-oriented applications with less code.

More details...


How EF works

  • Map domain classes to the db schema
  • Translate and execute LINQ queries to SQL
  • Track changes and save changes

Entity Data Model (EDM)

EDM is an in-memory representation of the entire metadata:

  • Conceptual Model: The conceptual model contains the model classes and their relationships
  • Storage Model: The storage model is the database design model which includes tables, views, stored procedures
  • Mapping: Mapping consists of information about how the conceptual model is mapped to the storage model

More details...


Approaches

  • Database First (traditional approach)
    • Desgin tables
    • EF generates domain classes
  • Code First (Very new and useful)
    • Create domain classes
    • EF generates database tables
  • Model First (Not recommend)
    • Create a UML diagram
    • EF generates domain classes and database

More details...


Database First or Code First

Code First Advantages:

  • Full versioning of database: You can bring your database to any version with running only one comment. It's extremely helpful if you are maintaining different versions of an application.
  • Productivity: Much faster to write code than use the mouse and a table designer.

There's not a best way, it depends on the situations.


後記

這是第一篇發表的文章,其實草稿匣裡還有好幾篇,但覺得除了線上課程的內容外還有很多官方提供的文件能夠補充,因此進度嚴重落後,一方面也在思考如何寫才能獲得自己想要的成果。總的來說,這些筆記的主要目的還是加深學習的印象,以後將試著精簡再精簡,不要花太多時間在文字和內容上琢磨,免得本末倒置了!


尚未有邦友留言

立即登入留言