Solved

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

Posted on 2012-03-17
5
328 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
  • 2
  • 2
5 Comments
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 250 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 35

Accepted Solution

by:
Miguel Oz earned 250 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best resource to learn entity framework 2 32
2 questions 10 25
imap mails 1 22
RLDC Reporting in Visual studio 11 13
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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