Last post Nov 15, 2016 02:44 PM by pizzaboy
Nov 08, 2016 09:56 AM|pizzaboy|LINK
I'm building a MVC project, but this has me completely baffled...
Why does the following reference not work?
private DataStore.Context db = new DataStore.Context();
But fully qualifying the object does?
private MyMVC.Models.DataStore.Context db = new MyMVC.Models.DataStore.Context();
Any help would be greatly appreciated.
Nov 09, 2016 06:55 AM|Nan Yu|LINK
Hi pizzaboy ,
What is the error when using "MyMVC.Models" reference .Please search your application to check whether other same name context exists . That may cause
Nov 10, 2016 06:35 AM|pizzaboy|LINK
I get the CS0246 error "The type or namespace name 'DataStore' could not be found (are you missing a using directive or an assembly reference?)" message.
Are the "Models", "Controllers" and "Views" private namespaces are something?
I come from a VB background so are just assuming you could do something like "Imports MyMVC.Models" then reference any namespaces/objects ("Datastore.Context") belonging to the import. Are the Imports and Using statements used differently?
Nov 15, 2016 11:20 AM|Zhi Lv - MSFT|LINK
Are the Imports and Using statements used differently?
Yes, they are different.
Create a using directive to use the types in a namespace without having to specify the namespace. A using directive does not give you access to any namespaces that are nested in the namespace you specify. More
details about Using, see:
The scope of the elements made available by an Imports statement depends on whether you specify element.
If you specify only namespace, all uniquely named members of that namespace, and members of container elements within that namespace, are available without qualification. If you specify both namespace and element, only the members of that element
are available without qualification. More information, check this article:
Nov 15, 2016 02:44 PM|pizzaboy|LINK
Finally someone answered this!
Presumed any good C# programmer (not limited in this forum) could have told me this!