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

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

问题描述

我不断听到实体框架流利的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-第一部分1介绍-和基本-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;}
}



[重点] 属性来自数据注释

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

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