Seed entity with owned property

后端 未结 5 1995
深忆病人
深忆病人 2021-02-12 13:41

I am trying to seed an user entity in my database. The User entity has an owend property EmailPermissions.

When I run the command

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-12 14:21

    In my scenario I wanted the owned-type property to be auto-initialed in the parent class:

    public class User
    {
      EmailPermissions _EmailPermissions;
      public EmailPermissions 
      {
        get => _EmailPermissions ??= new EmailPermissions();
        set => _EmailPermissions = value;
      }
    }
    

    When I tried to add seed data I got that nasty exception.

    The solution was to pass the User as anonymous type in its HasData call.

提交回复
热议问题