如何在伪造的 C# 中从具有相同值的总项目中生成固定数量的项目
How to generate fixed number of items out of total items with same value in Bogus C#
我正在尝试在 C# 中生成 3000 条假记录,条件是每 1000 条记录将具有相同的 UTC 毫秒时间戳 (update_time
),然后接下来的 1000 条将具有相同的 UTC 毫秒时间戳。如何实现?
private static IReadOnlyCollection<Document> GetDocumentsToInsert()
{
return new Bogus.Faker<Document>()
.StrictMode(true)
//Generate item
.RuleFor(o => o.id, f => Guid.NewGuid().ToString()) //id
.RuleFor(o => o.update_time, f => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();)
.Generate(3000);
}
// <Model>
public class Document
{
public string update_time {get;set;}
public string id{get;set;}
}
我不熟悉 Faker,但看起来你想要这样的东西:
private static IEnumerable<Document> GetDocumentsToInsert()
{
IEnumerable<Document> result = new List<Document>();
for (int x = 0; x < 3; ++x)
{
DateTimeOffset timeNow = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
IEnumerable<Document> temp = new Bogus.Faker<Document>()
.StrictMode(true)
//Generate item
.RuleFor(o => o.id, f => Guid.NewGuid().ToString()) //id
.RuleFor(o => o.update_time, f => timeNow;)
.Generate(1000);
result = result.Concat(temp);
}
return result;
}
我正在尝试在 C# 中生成 3000 条假记录,条件是每 1000 条记录将具有相同的 UTC 毫秒时间戳 (update_time
),然后接下来的 1000 条将具有相同的 UTC 毫秒时间戳。如何实现?
private static IReadOnlyCollection<Document> GetDocumentsToInsert()
{
return new Bogus.Faker<Document>()
.StrictMode(true)
//Generate item
.RuleFor(o => o.id, f => Guid.NewGuid().ToString()) //id
.RuleFor(o => o.update_time, f => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();)
.Generate(3000);
}
// <Model>
public class Document
{
public string update_time {get;set;}
public string id{get;set;}
}
我不熟悉 Faker,但看起来你想要这样的东西:
private static IEnumerable<Document> GetDocumentsToInsert()
{
IEnumerable<Document> result = new List<Document>();
for (int x = 0; x < 3; ++x)
{
DateTimeOffset timeNow = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
IEnumerable<Document> temp = new Bogus.Faker<Document>()
.StrictMode(true)
//Generate item
.RuleFor(o => o.id, f => Guid.NewGuid().ToString()) //id
.RuleFor(o => o.update_time, f => timeNow;)
.Generate(1000);
result = result.Concat(temp);
}
return result;
}