用虚拟数据填充 POCO 的最佳方法是什么?
我有一堆 POCO,它们都在一棵大树中相互关联。例如,这是顶级元素:
public class Incident : Entity<Incident>
{
public virtual string Name { get; set; }
public virtual DateTime Date { get; set; }
public virtual IEnumerable<Site> Sites { get; set; }
public Incident()
{
Sites = new HashSet<Site>();
}
}
树的结构类似于 Incident ->;站点->评估->子站点->图片
。 POCO 没有任何逻辑,只有一堆属性。我想做的只是用随机虚拟数据填充每个属性,这样我就可以编写一些搜索代码。如果我想创建大量虚拟数据,最好的方法是什么?
I have a bunch of POCOs that all relate to each other in a big tree. For example, this is the top-level element:
public class Incident : Entity<Incident>
{
public virtual string Name { get; set; }
public virtual DateTime Date { get; set; }
public virtual IEnumerable<Site> Sites { get; set; }
public Incident()
{
Sites = new HashSet<Site>();
}
}
The tree goes something like Incident -> Sites -> Assessments -> Subsites -> Images
. The POCO's don't have any logic, just a bunch of properties. What I want to do is just fill every property with random dummy data so I can write some search code. What's the best way of doing this if I want to create a large number of dummy data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会考虑使用 NBuilder。它可以让您做到这一点 - 使用非常简单的语法为您的对象创建随机数据。例如:
I would consider using NBuilder. It lets you do just that - create random data for your objects, using a pretty straightforward syntax. For example: