Columns having Referential Integrity/Foreign Key relation ship are not shown in EDM. Why?
- Hi All,
Columns having Referential Integrity/Foreign Key relation ship are not shown in EDM. Why?
When I remove referential integrity, all the properties are shown in EDM. However, when I add referential integrity in database, the respective columns are not shown in EDM.
Why is it? How to fix this problem.
Regards,
Jai
Answers
- Hi,
In EF1 the behavior is to create a navigation property between entities with foreign keys. That mean that you won't see the foreign key in the EDM but it exists.
In EF4 you have both navigation properties and also forreign keys as part of the EDM.
I hope it will help you.
Gil Fink- Marked As Answer byJai Mallesh Babu Thursday, October 29, 2009 4:13 PM
Hi Jai,
Gil is definitely correct! In the current version of Entity Framework (.NET 3.5 SP1), the foreign key relationship columns are defined as navigation properties. Unlike LINQ to SQL data class, we cannot have the foreign key column property in the entity class in current version of EF.
As Gil has said, in Entity Framework 4.0 (Visual Studio 2010), we can have a new association named foreign key association, which allows us to keep the foreign key column property in the entity class. For detail, please see http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx.
Have a great day!
Best Regards,
Lingzhi SunMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byJai Mallesh Babu Thursday, October 29, 2009 4:13 PM
All Replies
- Hi,
In EF1 the behavior is to create a navigation property between entities with foreign keys. That mean that you won't see the foreign key in the EDM but it exists.
In EF4 you have both navigation properties and also forreign keys as part of the EDM.
I hope it will help you.
Gil Fink- Marked As Answer byJai Mallesh Babu Thursday, October 29, 2009 4:13 PM
Hi Jai,
Gil is definitely correct! In the current version of Entity Framework (.NET 3.5 SP1), the foreign key relationship columns are defined as navigation properties. Unlike LINQ to SQL data class, we cannot have the foreign key column property in the entity class in current version of EF.
As Gil has said, in Entity Framework 4.0 (Visual Studio 2010), we can have a new association named foreign key association, which allows us to keep the foreign key column property in the entity class. For detail, please see http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx.
Have a great day!
Best Regards,
Lingzhi SunMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byJai Mallesh Babu Thursday, October 29, 2009 4:13 PM
- Thanks for reply Lingzhi ang Gil.
So in case if we release our product with 3.5v, there is no way to get those missing properties which have Foreign key relationships?
At this time, we are removing all relation ships in database which is a bad idea.
I understand that upgrading to 4.0v is the only option. Let me know if you have any alternatives.
Thank you,
Jai - Jai
You can navigate betwenn FK fields by the parent references, just like:
var
q = from p in db.TBLProduct
select new
{
p.IDProduct,
p.TBLCategory.IDCategory
}
using this way, you can navigate not only in the FK field, but in all fields of the child table!
Expect be helpfull!! Hi Jai,
Daniel is right! We can get the value of the foreign key column value by the navigation properties.
For detail, please see How to: Navigate Relationships Using Navigation Properties (Entity Framework).
Please feel free to let me know if you need any further assistance.
Have a nice weekend!
Best Regards,
Lingzhi SunMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.Hi Jai,
Do you need any further assistance? If so, please feel free to let me know.
Have a nice day!
Best Regards,
Lingzhi SunMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- I think you can close this thread.
Thanks for answers.
Regards,
Jai


