.net 4.5外键数据注释c# [英] .net 4.5 foreign key data annotation c#

查看:161
本文介绍了.net 4.5外键数据注释c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否在.net 4.5中不支持 [外键(blah)] 当我在数据输入模型中导入时,智能感知告诉我它不存在。相反的属性也是一样的。他们试图让我们使用流畅的api来进行这些类型的操作吗?流畅的api和数据注释是否有标准?

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 ?

型号:

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; }
    }
}


推荐答案

ForeignKey在.net 4.5中仍然非常活跃,检查:

ForeignKey is still very much alive in .net 4.5, check:

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.schema.foreignkeyattribute.aspx

您可能没有在项目中引用System.ComponentModel.DataAnnotations.dll程序集。

You might be missing a reference to System.ComponentModel.DataAnnotations.dll assembly in your project.

更新:
As @mtleising发表评论说,.net 4.5的 ForeignKeyAttribute 的命名空间是 System.ComponentModel.DataAnnotations。模式

这篇关于.net 4.5外键数据注释c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆