我已经创建了这样的简单模型:
CheckBoxTreeItem<Object> item = new CheckBoxTreeItem<>(new Hyperlink("abc"));
CheckBoxTreeItem<Object> item2 = new CheckBoxTreeItem<>("Hello World");
CheckBoxTreeItem<Object> item3 = new CheckBoxTreeItem<>("42");
CheckBoxTreeItem<Object> item4 = new CheckBoxTreeItem<>(new Hyperlink("def"));
item.getChildren().setAll(item2, item3, item4);
TreeView<Object> treeView = new TreeView<>(item);
treeView.setCellFactory(tv -> new CheckBoxTreeCell<Object>() {
private final HBox graphicWrapper = new HBox();
{
graphicWrapper.setAlignment(Pos.BASELINE_LEFT);
}
@Override
public void updateItem(Object item, boolean empty) {
graphicWrapper.getChildren().clear();
super.updateItem(item, empty);
if (!empty && (item instanceof Node)) {
// replace graphic & text
setText(null);
graphicWrapper.getChildren().setAll(getGraphic(), (Node) item);
setGraphic(graphicWrapper);
}
}
});
}
所以我开始在DbContext中映射我的模型。但是现在我想和Bogus和Faker一起播种。 Gendertype是一个Enum,我想在这3个中产生1个。
这是我目前为播种的代码:
using System;
using System.Collections.Generic;
namespace Resa.Models
{
public enum GenderType : byte {
Unknown = 0,
Male = 1,
Female = 2,
NotApplicable = 9
}
public class Profile
{
public Int64 Id { get; set; }
public string FirstName { get; set; }
public string SurName { get; set; }
public GenderType Gender { get; set; } // temporary
public Nullable<DateTime> DayOfBirth { get; set; }
public bool Verified { get; set; }
public string Picture { get; set; }
public DateTime CreatedAt { get; set; }
public Nullable<DateTime> UpdatedAt { get; set; }
public Nullable<DateTime> DeletedAt { get; set; }
public List<Listing> Listings { get; set; }
public List<Address> Addresses { get; set; }
}
所以问题是:如何在不违反gendertype的情况下选择随机枚举?