Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

adding an interface to my code generated classes e.f 4.1

Posted on 2012-03-17
5
Medium Priority
?
334 Views
Last Modified: 2012-06-27
Hi,

I have created a load of classes from my .edmx using add code generation item.

I want my classes to implement an interface but to do this I have had to create a partial class.

public partial class Costume : IEntity,IDisposable
{

This would mean that for every class coming out of my model I would also need to create a partial class within my app.

Is this normal or is there a better way of doing things?

I'd appreciate a swfit reply on this so I don't go too far in the wrong direction.

Thanks in advance.

One other thing to note, I know I could amend the generated classes but then if I have to re-generate for some reason I would lose my changes....
0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 1000 total points
ID: 37732610
basically you need to use POCO and Self tracking entities feature of EF.
Here is the msdn article series on the same:-
http://blogs.msdn.com/b/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx
0
 

Author Comment

by:scm0sml
ID: 37732971
Haven't I already done that?

I have ended up with a load of POCO using the add code generation item which created my classes from the model.

My question point is that if I implement my interfaces on those classes and then in the future add more fields to my database hence to my model and then want to re-generate my classes from the model in add my new fields as properties then I would lose all my implemented interfaces....?
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37733066
don't generate classes from your model or edmx file.
Write them manually or using T4 template.

This allows you to make changes to your entities without worrying about updating any edmx file.

Also i would suggest you go through the concepts of Domain Driven Design to better understand the working of Domain Entities and how they must be represented in your application....
0
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 1000 total points
ID: 37733576
My advice will depend on whether you are expecting a lot of changes between your interface implementation code in your underling model. If this value is small then doing the partial class implementation is OK,  your new implementation must be on a separate class(file) in your application.
e.g if your generated class declaration is:
public partial class Costume : IEntity,IDisposable

then your new class will look like:
public partial class Costume : IEntity,IDisposable, IMyNewinterface

As you can see  even if you regenerate the entity class your implementation is only affected if you change properties that your new class is accessing it.

Note:  you can use extension methods (http://msdn.microsoft.com/en-us/library/bb383977.aspx) but  you still need to check that modifications to the entity classes are not breaking your extension methods
0
 

Author Comment

by:scm0sml
ID: 37736618
Hi mas_oz2003,

This line:
"e.g if your generated class declaration is:
public partial class Costume : IEntity,IDisposable"

How would the generated class get the interface implementiations or do you mean I would have added them manually?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question