什么是实体框架流畅的api? [英] What is Entity Framework fluent api?

查看:120
本文介绍了什么是实体框架流畅的api?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在听取关于实体框架流畅的信息,但我正在努力寻找一个很好的参考。这是什么?

I keep hearing about the Entity Framework fluent-api but I am struggling to find a good reference on this. What is it?

我们使用实体框架和提供的建模工具。这是一切吗?或者是不同的东西?

We use the entity framework and the modeling tool provided. Is that all that is? Or is it something different?

同样,如果不是太广泛的问题,POCO是什么?我知道它代表普通老CLR对象,但对于使用EF的人来说,这对于我来说意味着什么对于设计师模型工具呢?如果这个问题太模糊,那么请忽略它。我只是在这里学习,你愿意提供的任何信息都是有帮助的。

Similarly, if it's not too broad a question, what is POCO? I know it stands for Plain Old CLR Objects, but what does that mean to me as somebody who uses EF already with the designer model tool? If that question is too vague then please ignore it. I'm just learning here and any information you are willing to provide is helpful.

推荐答案

实体框架4.1引入了代码第一个方法编写数据库模型。这也称为POCO(普通老CLR对象)。这个想法是,您可以从这些类中构建数据库,而不是首先构建数据库,并从中创建一个模型。

Entity Framework 4.1 introduces the code first approach of writing database models. This is also called POCO (Plain Old CLR Objects). The idea is that you can build your database from these classes, rather then building the database first and creating a model from that.

有很多好的博客文章和MSDN这方面的文件。一个好的开始是

There are tons of good blog articles and MSDN documentation on this. A good place to start would be

http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-fluent-api -samples.aspx

http://weblogs.asp.net/scottgu/archive/2010/12/08/announcing-entity-framework-code-first- ctp5-release.aspx

http://weblogs.asp.net/manavi/archive/2011/03 /27/associations-in-ef-4-1-code-first-part-1-introduction-and-basic-concepts.aspx

问候流畅的API,这基本上是使用EF类构建你的数据库,例如:

Regards the fluent API, this is basically using the EF classes to build your database e.g.:

modelBuilder.Entity<Category>().HasKey(c => c.CategoryCode);

所以你手动指出类别表有一个名为`CategoryCode'的主键。您也可以这样声明PK:

So you're manually stating that the Category table has a primary key named `CategoryCode'. You can also declare the PK like this:

public class Category
{
    [Key]    
    public int CategoryCode { get; set;}
}

[Key] 属性来自数据注释

这篇关于什么是实体框架流畅的api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆