Solved

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

Posted on 2012-03-17
5
326 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why Does This Page Not Show Up? 4 24
Error in page 3 46
IIS issues - Convert to Application - APS.NET v4.0 3 23
Pagebreak issue while printing the aspx page 3 16
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now