views:

446

answers:

3

hello, I use Entity Data Model but I have aproblem: If a table e.g Customers have categoryId(foreign key from table category) it is not appear in cutomers entity???? so how can i retrive this value or set it?

+1  A: 

The Entity Framework does render the actual property itself, it will create an property of Type Category. i.e.:

Customer.Category = new Category()

The Entity Framework will handle the references / foreign keys internally.

Colin
ok but I have another foreign key(category parentId) in category table(parentId foreign key from categoryid in the same table)how can I get this field?
+1  A: 

Colin's answer is 100% accurate and true - for the currently available release of the Entity Framework (with .NET 3.5 SP1).

For the upcoming and not-yet-released EF v2 (or EF 4??) that will ship with .NET 4.0 sometime in the future, the EF team has added what they call "foreign key associations", which in essence will allow you to just specify the foreign key value (e.g. CategoryID) instead of having to create / load / assign the whole associated entity.

See more in these excellent posts:

DISCLAIMER: this is pre-release information about a not-yet-released product and with no delivery date officially announced - you can download a Beta1 for now.

Marc

marc_s
ok but I have another foreign key(category parentId) in category table(parentId foreign key from categoryid in the same table) how can I get this field?
You would then use Category.Category.Id (open the EF diagram and select the Category Entity. It should give you a list of all avaiable properties.)
Colin
@Wafaa: if you need to get at the ParentID in the referenced Category, then you'd have to load the whole Category entity, and then in that entity set the "ParentID" column
marc_s
And whne you have the diagram open you could choose to rename the parent Category Property (Which out of the box will probably have a name Like Category, or Category1) to CategoryParent or something similar
Colin
the upcoming and not-yet-released EF v2 (or EF 4)is it avaliable now?
If I need to add new customer how can I set the value categoryId( foreign key column?
A: 

Can't you do it this way ?

Customer.CategoryReference.EntityKey = Key;
Jacob