Invalid using ; added to generated migration file because this simple project has no default namespace.
Setup https://gist.github.com/natemcmaster/90e2388c0ee1d29f440a.
Using dnx 1.0.0-beta6-12114 , EF 7.0.0-beta6-13584
dnx . ef migration add Initial
produces 20150624223653_Initial.Designer.cs which includes this at the top of the file:
c#
using System;
using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Relational.Migrations.Infrastructure;
using ;
The same using block appears in ModelSnapshot.cs
Related to #2261
this issue still occurs, and all entity under Proj.Models....
FWIW, more customers will be hitting this now that we're creating more CLI docs. See https://github.com/aspnet/Scaffolding/issues/599
@Rick-Anderson Why do we have sample projects with no default namespace?
@ajcvickers maybe this is rare. When you follow the instructions at aspnet/Scaffolding#599, you get no namespace. The project has a namespace, not the DC.
It's not clear the CLI requires you to add a namespace for the DC.
@Rick-Anderson It may not be required, but it's certainly best practice. If we have some guidance or tooling that is by default creating classes not in any namespace, then I think the real thing to address is that guidance and tooling. (Think about what VS does--every project you create or class you add to it is in a namespace by default; it's idiomatic to .NET.)
@ajcvickers does the bug belong to .NET CLI for not warning on -dc MovieContext in the following command?
dotnet aspnet-codegenerator razorpage -m Movie -dc MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries
@Rick-Anderson I don't know enough about how the templating works to know what part should be ensuring a namespace. Maybe ask whoever authored the templates?
@ajcvickers But it is generating invalid code. You're not required to have a NS. It seems like it would be better to fix the producer of bad generated code than fixing the inputs.
@Rick-Anderson We didn't close this--we are intending to fix it. We will re-triage the priority. I still believe the bigger issue is that something out of Microsoft if generating a class without a namespace. That's something we should just not do.
@ajcvickers I'm guessing this is low priority FWIW.
I sometimes create VS projects and remove the namespace - just to cut down on noise/indenting on rendered code. Even if the scaffolder forces a namespace, nothing stops the user from removing the namespace. I'll shut up now.
Would love to see this problem go away. Yes, every class should have a namespace but this is a rough punishment. ;)
Where empty string is being injected. Just need a check there before printing out using statement for it.
Awesome, I was just about to clone the repo and fix this :)
@BennyM I love the enthusiasm! Feel free to check out some of our other up-for-grabs issues if you're still interested in submitting a PR. 馃槈
oh didnt see that #2467 !!! Thank you !!!
Most helpful comment
@BennyM I love the enthusiasm! Feel free to check out some of our other up-for-grabs issues if you're still interested in submitting a PR. 馃槈