Reputation: 171
Is the [foreign key("blah")]
not supported in .net 4.5 anymore ? When I import in the dataannotations model, intellisense tells me that it doesn't exist. The same happens with the inverse property. Are they trying to get us to use the fluent api for these types of opperations instead ? Are there any standards for fluent api vs data annotations ?
Model :
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace DevCentral.Entities
{
public partial class Category
{
[Key]
public int Id { get; set; }
[MaxLength(75), MinLength(1)]
public string Name { get; set; }
[Required]
public int ClassificationId { get; set; }
[ForeignKey("ClassificationId"), InverseProperty("Categories")]
public virtual Classification Classification { get; set; }
}
}
Upvotes: 1
Views: 7336
Reputation: 2459
ForeignKey is still very much alive in .net 4.5, check:
You might be missing a reference to System.ComponentModel.DataAnnotations.dll assembly in your project.
Update:
As @mtleising commented, the namespace for ForeignKeyAttribute
as of .net 4.5 is System.ComponentModel.DataAnnotations.Schema
Upvotes: 3