从实体框架数据库第一自动生成的代码生成接口 [英] Generating Interfaces from entity framework database first auto-generated code

查看:428
本文介绍了从实体框架数据库第一自动生成的代码生成接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC3,C#4.0和Entity Framework在Visual Studio 2010中我生成我从数据库中EDMX和Designed.cs文件。我再从Designer.cs文件作为我的n图层结构的一部分实体生成接口。

I am using MVC3, C# 4.0 and Entity Framework in Visual Studio 2010. I am generating my edmx and Designed.cs files from a database. I am then generating interfaces from the entities in the Designer.cs file as part of my nLayer structure.

原代码是

public partial class DataEntrySummary : EntityObject

这就变成了

public partial class DataEntrySummary : EntityObject, Mb.Interface.IDataEntrySummary

我担心的是,当数据库更改我(和它会),并重新生成EDMX文件,我将失去所有的接口定义。

My concern is that when the database changes (and it will) and I regenerate the edmx files I will lose all the interface definitions.

有没有达到同样的效果,而无需重新生成接口的更好的方法。

Is there a better way of achieving the same result without having to regenerate the interfaces.

感谢您

推荐答案

EF生成与部分关键字的类,这样就可以通过向实体添加额外的功能。创建另一个文件,并将该接口具体的东西有

EF generates the classes with the partial keyword so that you can add extra functionality to the entities by creating another file and place the interface specific stuff there.

public partial class DataEntrySummary : Mb.Interface.IDataEntrySummary
{
}

这些文件将不会得到受影响时,EF更新模型。

These files will not get affected when EF updates the model.

这篇关于从实体框架数据库第一自动生成的代码生成接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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