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 Enti开发者_开发问答ty 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.
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.
精彩评论