【发布时间】:2021-07-08 19:59:52
【问题描述】:
有这个:
var SampleNames = new PersianName[] {
new XName("Sara","Dianov"),
new XName("Eliza","Raas"),
new XName("Robert","Smith")
};
var theFaker = new Faker<Architect>()
.RuleFor(h => h.User.NameBundle, f => f.PickRandom(SampleNames))
收到此错误:
Error: System.ArgumentException:
Your expression 'h.User.NameBundle' cant be used.
Nested accessors like 'o => o.NestedObject.Foo' at a parent level are not allowed.
You should create a dedicated faker for NestedObject like new Faker<NestedObject>().RuleFor(o => o.Foo, ...)
with its own rules that define how 'Foo' is generated.
See this GitHub issue for more info: https://github.com/bchavez/Bogus/issues/115
我该如何解决这个问题?已阅读错误消息中提供的链接,顺便说一句,我还无法解决它。
我想为h.User.NameBundle 分配一个随机的XName 元素,如果我真的需要第二个faker 并且不确定如何使用单独的Faker 来实现这一点,请不要这样做。
【问题讨论】: