Forum


HomeHomePremiumPremiumDevelopmentDevelopmentEF Many to ManyEF Many to Many
Previous
 
Next
New Post
4/22/2014 4:42 AM
 

Hi Scott,

I'm trying to move away from DAL and going to Entity Framewaork.

I'm following the Entity Framework video you have done. All is going fine with simple entities. 

Now I'm trying to create a Many to Many relationship from "Courses" and "Tags" - One course can have many tags - A tag can be part of many courses.

On the "interface ICourseModel" I'm not sure how to declare the "Tags" property. 

I have tried:

EntityCollection<ITagModel> Tags { get; set; }


But that doesn't seem to work.

How should this be done?

Thanks,

Aderson

 
New Post
4/22/2014 2:40 PM
 

Aderson,

I'm not sure you need to define interfaces for your entities.  The reason I used them in the Data Access tutorial is so I could use the same entities regardless of the data access method.  For you, it may just over complicate since EF is generating your entity implementation code each time you change something in the designer.

I would model the relationship using the designer interface (.edmx) and see how EF builds the code in the designer file.

That being said I took a look at one of the designers on a project I did in EF.  It was a 1-M relationship and on the one side, the entity contained a property:

public EntityCollection<ManyEntity> ManyEntity { get {...} set {...} }

So it seems like your interface is correct.

If you need more help, hit me up on Skype after work hours.

Good luck!

 
New Post
4/23/2014 3:07 AM
 

Thanks Scott.

You are very right. I don't need interfaces as I'm just using EF.

It is all fine now. At some point I will send you my project so you can have a look and make recommendations in terms of best practices.

Cheers,

Aderson

 
Previous
 
Next
HomeHomePremiumPremiumDevelopmentDevelopmentEF Many to ManyEF Many to Many



Try FREE
30 days money back guaranteed