How to use interface properties with CodeFirst

后端 未结 7 2064
自闭症患者
自闭症患者 2020-12-01 01:17

I have the following entities:

public interface IMyEntity
{
    [Key]
    int Id { get; set; }
    IMyDetail MyDetail { get; set; }
    ICollection

        
7条回答
  •  -上瘾入骨i
    2020-12-01 01:54

    I had this issue too on some on my models and not others and tried using the accepted answer. Then I dug a bit deeper as to what was different on the models that worked.

    Fix was to change from using ICollection to use IEnumerable instead and the issues went away, so far.

    This removed the need to use the below code in accepted answer:

    public interface IParent
    where TChild : IChild
    {
    ICollection Children { get; set; }       
    

    and it became

    public interface IParent
    {
    IEnumerable Children { get; set; } 
    

    which is much simpler.

提交回复
热议问题