EntityType“品种”未定义键。定义此EntityType的键 [英] EntityType 'Breed' has no key defined. Define the key for this EntityType

查看:175
本文介绍了EntityType“品种”未定义键。定义此EntityType的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它可能看起来像已经问过的问题的副本。
i已经检查了所有解决方案,但我的问题是不合逻辑的。

It may looks like a copy of already asked question. i have checked all the solutions but my problem is non-logical.

public class Breed
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    int id { get; set; }
    string name { get; set; }
}

错误Kamdhenu.Models.Breed::EntityType'Breed'没有密钥定义。定义此EntityType的键。
品种:EntityType:EntitySet品种基于未定义键的类型品种。

Error Kamdhenu.Models.Breed: : EntityType 'Breed' has no key defined. Define the key for this EntityType. Breeds: EntityType: EntitySet 'Breeds' is based on type 'Breed' that has no keys defined.

推荐答案

将属性定义为 public 。没有指定者,默认情况下它们为私有,EF不会识别和映射私有属性:

Define the properties as public. Without specifier they are private by default and EF won't recognize and map private properties:

public int id { get; set; }
public string name { get; set; }

这篇关于EntityType“品种”未定义键。定义此EntityType的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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