bchavez / Bogus

:card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.
Other
8.76k stars 498 forks source link

Bogus is not working with linqpad ORM #10

Closed ghost closed 8 years ago

ghost commented 8 years ago

When I try to use bogus with linqpad ORM it throws this exception:

ArgumentException: Expression was not of the form 'x => x.property'.

bchavez commented 8 years ago

Hi there @swellfr ! Thanks for reporting the issue. Could you give me an example of how your using Bogus in LINQPad? If you provide an example that throws ArgumentException, I can try to reproduce the issue on my side.

Thanks, Brian

ghost commented 8 years ago

To create the database I made it with EF CodeFirst.

Take a simple POCO

public class Person
{
    public Guid Id {get; set;}
    public string Name {get; set;}
}

Now in Linqpad create a query, select the database

and add the following code:

var personGenerator= new Faker<Person>()
    .RuleFor(p => p.Name, f => f.Name.LastName());

var p = personGenerator.Generate();

If you try it, Linqpad will throw

bchavez commented 8 years ago

Hi @swellfr , Thanks for the example.

I copy/pasted your example in LINQPad, the first error I got was:

CS0136 A local or parameter named 'p' cannot be declared 
in this scope because that name is used in an enclosing local 
scope to define a local or parameter

The problem was .RuleFor(p => conflicting with var p = personGenerator. So I changed var p to fakePerson. See below:

screen529

Could you try my example in your LINQPad? If it runs, at least we know Bogus is working in LINQPad by itself. The problem could be further down the pipeline with EF.

If Bogus is working, could you give me an example EF query you're trying to use with Bogus that is probably throwing the exception?

ghost commented 8 years ago

The database is coming from ASP.NET Identity and it has been created with Code First.

Bogus throws only when you use Linqpad's ORM

bogus

bchavez commented 8 years ago

Thanks @swellfr , I'm able to reproduce the error now. Your screenshot helps a lot. Give me a few to try to understand what's going on under the hood.

bchavez commented 8 years ago

Ah, I see what's going on now. LINQPad, is generating AspNetUsers table columns as fields, not properties. Bogus is expecting expressions of p => p.Property, not p => p.Field. I'll have this fixed soon.

bchavez commented 8 years ago

Hi @swellfr , you should be good to go now.

Update Bogus and give 3.0.4 a try. Bogus now works on fields, not just properties. :+1:

Thanks again for reporting the issue.

Feel free to re-open the issue if you encounter any problems. Thx m8.

Brian

screen532

ghost commented 8 years ago

Works like a charm! :+1: