views:

50

answers:

1

I'm starting to use Entity Framework. Let's say I have to Entity from my tables in DB.

Here is the table schema

Profiles

  • ProfileId
  • FirstName
  • LastName

Hobbies

  • Id
  • HobbyName
  • OwnerId

So one profile can have many hobbies.

My Entity Framework:

ProfileEntity

  • ProfileId
  • FirstName
  • LastName
  • Hobbies (collection of HobbyEntity) note: this created by the Association tool

HobbyEntity

  • Id
  • HobbyName
  • Owner (type of ProfileEntity) note: this created by the Association tool, for me this property is not important

my question: should I use the "Association" tool to make the relationship between the two entities, which in result create a property of each entity (in ProfileEntity will create a HobbyEntity and vica versa) or should I not use the association and only add a scalar property manually such as List<HobbyEntity> in my ProfileEntity and OwnerId in HobbyEntity.

A: 

This depends on which Entity Framework are you using.

If you are using EF 1.0 (the one released with net framework 3.5 sp1) then you should use the designer, because only then the relationship will be managed properly.

However if you are using EF 2 (to be released with net framework 4.0) then the answer is that you can do both, because EF 2 (4.0) supports code-only and code-first strategies.

kubal5003
Unfortunately "Code First/Code Only" will not be included with the upcoming EF 4.0 release. :-( http://blogs.msdn.com/adonet/archive/2010/02/18/entity-framework-feature-ctp-3-now-available.aspx#9966073
mxmissile
Look at the dates before voting down.
kubal5003