简体   繁体   中英

Can I seed data on required property in EF?

Is it recommended to seed data with [Required] property?

To be more specific let us take this example

public class Equipment : BaseEntity
    {
        #region Properties
        public int EquipmentId { get; set; }
        [Required]
        public string EquipmentName { get; set; }
        public EquipmentType EquipmentType { get; set; }
        #region Navigation Properties
        public ICollection<EventEquipment> EventEquipments { get; set; }
        #endregion

        #endregion

        #region Constructors
        public Equipment()
        {

        }
        #endregion

        #region Methods
        #endregion
    }
}

can I use EquipmentName property to seed data? Is this the recommended approach? If not, what is the best property to use to seed data?

If you wanna seed data, better way is to seed whole objects, not only single property. On the other hand, there's no formal restriction to seed required property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM