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