tareqimbasher / NetPad

A cross-platform C# editor and playground.
MIT License
1.36k stars 68 forks source link

error during scaffolding #55

Closed lenscas closed 1 year ago

lenscas commented 1 year ago

I just installed netpad version 0.4 on macos, and then installed the .NET7 SDK and later tried installing the 6 as well. In both cases though it fails to scaffold against my postgresql database with the error:

System.Exception: Scaffolding process failed with exit code: 1. Errors: Specify --help for a list of available options and commands.
Unrecognized option '--namespace'
   at NetPad.Data.EntityFrameworkCore.Scaffolding.EntityFrameworkDatabaseScaffolder.RunEfCoreToolsAsync() in /home/tips/Source/TIPS/NetPad/src/Infrastructure/NetPad.Infrastructure/Data/EntityFrameworkCore/Scaffolding/EntityFrameworkDatabaseScaffolder.cs:line 160
   at NetPad.Data.EntityFrameworkCore.Scaffolding.EntityFrameworkDatabaseScaffolder.ScaffoldAsync() in /home/tips/Source/TIPS/NetPad/src/Infrastructure/NetPad.Infrastructure/Data/EntityFrameworkCore/Scaffolding/EntityFrameworkDatabaseScaffolder.cs:line 59
   at NetPad.Data.EntityFrameworkCore.Scaffolding.EntityFrameworkDatabaseScaffolder.ScaffoldAsync() in /home/tips/Source/TIPS/NetPad/src/Infrastructure/NetPad.Infrastructure/Data/EntityFrameworkCore/Scaffolding/EntityFrameworkDatabaseScaffolder.cs:line 69
   at NetPad.Data.EntityFrameworkCore.EntityFrameworkResourcesGenerator.GenerateSourceCodeAsync(DataConnection dataConnection, DotNetFrameworkVersion targetFrameworkVersion) in /home/tips/Source/TIPS/NetPad/src/Infrastructure/NetPad.Infrastructure/Data/EntityFrameworkCore/EntityFrameworkResourcesGenerator.cs:line 61
   at NetPad.Data.DataConnectionResourcesCache.<>c__DisplayClass11_0.<<GetSourceGeneratedCodeAsync>b__0>d.MoveNext() in /home/tips/Source/TIPS/NetPad/src/Core/NetPad.Application/Data/DataConnectionResourcesCache.cs:line 80
--- End of stack trace from previous location ---
   at NetPad.Scripts.ScriptEnvironment.AppendDataConnectionResourcesAsync(RunOptions runOptions, DataConnection dataConnection) in /home/tips/Source/TIPS/NetPad/src/Core/NetPad.Application/Scripts/ScriptEnvironment.cs:line 98
   at NetPad.Scripts.ScriptEnvironment.RunAsync(RunOptions runOptions) in /home/tips/Source/TIPS/NetPad/src/Core/NetPad.Application/Scripts/ScriptEnvironment.cs:line 62

The same seems to be happening on version 0.3.1

tareqimbasher commented 1 year ago

@lenscas make sure you have the dotnet ef tool installed and that it's v6 or higher:

dotnet tool update --global dotnet-ef

Then restart NetPad. You must have an older version of the ef tool, the namespace option was introduced with .NET 5. To see your current version:

dotnet ef --version
lenscas commented 1 year ago

ah, that makes sense. Totally forgot about ef and yes, I had an old version installed (3.0.0). Updating it seemed to have fix the issue. Might be worth to add it to the list of dependencies, especially the check it did when I first started it?

Anyway, thanks for the help :)

tareqimbasher commented 1 year ago

Agreed, I'll add that. Its currently checking for the existence of the ef tool, but not its version.

tareqimbasher commented 1 year ago

PR merged. Change will go out with next release.

lenscas commented 1 year ago

Awesome. Sounds great :tada:

I already used netpad a few times to help debug complicated queries and the like. Linqpad is not an option for me as I am not using Windows. So, thanks for making netpad :)

tareqimbasher commented 1 year ago

I'm glad you're enjoying it. It makes my day hearing you were able to use NetPad to better engineer a solution, these type of comments make it all worth while :) Thanks for sharing!

lenscas commented 1 year ago

Not just engineer a better solution, but actually make an EFCore query work. It had become rather big and apparently in some situations had problems with something being null that it didn't expect.

EFCore being efcore didn't really tell me what field or anything close to that was the problematic field.

Netpad allowed to me to quickly test out versions of it that forced client side evaluation at different parts of the query until I got an idea of what and where the problem was.

Which is a lot easier to do in netpad than "making a change in the codebase, waiting for it to compile and then making a request while staring at the console output while you make the problematic request which inevitably also floods the console"

It also helped me design a query from scratch after I noticed that the query I was using was slow. I already knew the problem in the generated SQL and now what SQL had to be generated in order to fix it but... getting there was not easy as EFCore just didn't support the operation natively that I needed (distinct on).

tareqimbasher commented 1 year ago

That's awesome! :tada: Very happy you were able to traverse that hill and I couldn't be happier with how NetPad helped you do that. Thank you again for sharing!!