Solved

[ForeignKey] not working in System.ComponentModel.DataAnnotations

Posted on 2013-05-19
1
585 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Help 27 57
JSON  parse help 7 40
Iteration Help (Asp.net VB) 5 24
Google Maps with Webforms 1 10
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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