I have a the following POCO:
public class GdataHealthTableModel : AuditedEntity
{
public GdataHealthTableModel()
{
PrevHealthAssessment = new HashSet<HealthPrevHealthAssessmentEnum>();
}
public HashSet<HealthPrevHealthAssessmentEnum> PrevHealthAssessment { get; set; }
}
but this does not generate a migration for the column PrevHealthAssessment . So what is the correct construct to be able to store multiple enum members so that EF "understands it" and will generate a migration?
You can add a new entity and name it eg PrevHealthAssessment
which will have the HealthPrevHealthAssessmentEnum
as a property.
public class PrevHealthAssessment
{
public int Id { get; set; }
public HealthPrevHealthAssessmentEnum HealthPrevHealthAssessment { get; set; }
}
In GdataHealthTableModel
, add a collection of the newly created entity like this:
public ICollection<PrevHealthAssessment> PrevHealthAssessments {get; set; }
You need to use the ICollection type.
public class GdataHealthTableModel : AuditedEntity
{
public GdataHealthTableModel()
{
PrevHealthAssessment = new HashSet<HealthPrevHealthAssessmentEnum>();
}
public ICollection<HealthPrevHealthAssessmentEnum> PrevHealthAssessment { get; set; }
}
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.