[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2012-03-17
5
Medium Priority
?
336 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

834 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