The key component 'Id' is not a declared property on type 'TypeName', when using base class and private setter

后端 未结 2 1788
悲&欢浪女
悲&欢浪女 2021-01-19 17:39

I want to use an abstract base class for entities, which is not mapped on any table:

public abstract class Entity
{
    public virtual int Id { get; private          


        
相关标签:
2条回答
  • 2021-01-19 18:21

    EF likes to access all keys. Try using protected so the assembly can access the ID but externals cant. Seems like a reasonable question for the EF team to me.

    See related post Does the Entity Framework code first support readonly navigation property

    0 讨论(0)
  • 2021-01-19 18:25

    make setter of id in entity class protected :

    public abstract class Entity
    {
        public virtual int Id { get; protected set; }
    }
    

    i tried this . it will be work

    0 讨论(0)
提交回复
热议问题