One or more validation errors were detected during model generation when establishing EF access to the database schema

Source: Internet
Author: User

The reason is because I did not declare a primary key for a property in the entity class when I was in the Realist class, that is, the [key] attribute is used to label the attribute, so that dbcontext can find the corresponding primary key on the database.

usingSystem.ComponentModel.DataAnnotations.Schema;usingSystem.ComponentModel.DataAnnotations;usingSystem;namespacefeng.entity{[Serializable] [Table ("Dict_sample")]     Public classdict_sample {[Key]//attributes that must be added, corresponding to the database primary key[Column ("sam_id")] [Stringlength ( A)]         Public stringsam_id {Get;Set; } [Column ("Sam_name")] [Stringlength ( -)]         Public stringSam_name {Get;Set; } [Stringlength ( -)] [Column ("Sam_code")]         Public stringSam_code {Get;Set; } [Stringlength ( A)] [Column ("Sam_incode")]         Public stringSam_incode {Get;Set; } [Stringlength ( A)] [Column ("Sam_type")]         Public stringSam_type {Get;Set; } [Stringlength ( -)] [Column ("sam_py")]         Public stringSam_py {Get;Set; } [Stringlength ( -)] [Column ("SAM_WB")]         Public stringSAM_WB {Get;Set; } [Column ("Sam_seq")]         Public intSam_seq {Get;Set; } [Stringlength (1)] [Column ("Sam_del")]         Public stringSam_del {Get;Set; } [Stringlength ( -)] [Column ("Sam_custom_type")]         Public stringSam_custom_type {Get;Set; } [Stringlength ( -)] [Column ("Sam_trans_code")]         Public stringSam_trans_code {Get;Set; } }}

One or more validation errors were detected during model generation when establishing EF access to the database schema

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.