建立EF访问数据库架构时,出现One or more validation errors were detected during model generation

Posted cellphoneyeah

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了建立EF访问数据库架构时,出现One or more validation errors were detected during model generation相关的知识,希望对你有一定的参考价值。

原因是因为我在写实体类的时候没有为实体类中的属性声明一个主键,即用[key]特性标注在属性上,这样DbContext才能为我们在数据库上找到对应的主键

using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System;
namespace Feng.Entity
{
    [Serializable]
    [Table("dict_sample")]
    public class Dict_sample
    {
        [Key]//必须要添加的特性,要和数据库主键对应
        [Column("sam_id")]
        [StringLength(12)]
        public string Sam_id
        { get; set; }

        [Column("sam_name")]
        [StringLength(50)]
        public string Sam_name
        { get; set; }

        [StringLength(18)]
        [Column("sam_code")]
        public string Sam_code
        { get; set; }

        [StringLength(12)]
        [Column("sam_incode")]
        public string Sam_incode
        { get; set; }

        [StringLength(12)]
        [Column("sam_type")]
        public string Sam_type
        { get; set; }

        [StringLength(18)]
        [Column("sam_py")]
        public string Sam_py
        { get; set; }

        [StringLength(18)]
        [Column("sam_wb")]
        public string Sam_wb
        { get; set; }

        [Column("sam_seq")]
        public int Sam_seq
        { get; set;
        }

        [StringLength(1)]
        [Column("sam_del")]
        public string Sam_del
        { get; set; }

        [StringLength(18)]
        [Column("sam_custom_type")]
        public string Sam_custom_type
        { get; set; }

        [StringLength(100)]
        [Column("sam_trans_code")]
        public string Sam_trans_code
        { get; set; }

    }
}

 

以上是关于建立EF访问数据库架构时,出现One or more validation errors were detected during model generation的主要内容,如果未能解决你的问题,请参考以下文章

“Validation failed for one or more entities”异常的解决办法

命令行运行ionic run android 出现running one or more of the platforms Error

晚上打开eclipse时碰到这个问题 :Workspace in use or cannot be created, choose a different one.

Tomcat Deployment failure ,locked one or more files

Mysql错误:The server time zone value is unrecognized or represents more than one time zone

EF架构~codeFirst从初始化到数据库迁移