Solved

[ForeignKey] not working in System.ComponentModel.DataAnnotations

Posted on 2013-05-19
1
572 Views
Last Modified: 2013-05-23
I am using System.ComponentModel.DataAnnotations in MVC 4 and I am able to specify [Key] for the primary key but [ForeignKey] does not come up in the intellisense nor can I just type in [ForeignKey] without getting an error. Nothing that I have found yet directs me to a possible solution.

Can anyone help?
0
Comment
Question by:AmbassadorSpock
1 Comment
 
LVL 16

Accepted Solution

by:
Stephan earned 500 total points
ID: 39180692
The ForeignKeyAttribute is available in namespace "System.ComponentModel.DataAnnotations.Schema" inside library "System.ComponentModel.DataAnnotations.dll, v4.0.0.0"

This attribute is only available on .NET 4.5 (and not 4.0)
http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.schema.foreignkeyattribute.aspx

If you are working in .NET 4.0 consider using the AssociationAttribute:
http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.associationattribute(v=vs.100).aspx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now