Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

c# - Generating Interfaces from entity framework database first auto-generated code

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.

The original code is

public partial class DataEntrySummary : EntityObject

which then becomes

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

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.

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
{
}

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...