How to add a “using” statement to the System.Data.Entity namespace
Solution 1
At the top of your file there should be couple lines, each starting with using
and namespace after that keyword.
Add another one there, to the namespace mentioned in your tutorial:
using System.Data.Entity;
You can find more information about using
on MSDN: using
Directive (C# Reference)
Solution 2
Although your question is about the using
statement, I believe you mean the using
directive.
Using Directive
To allow the use of types in a namespace so that you do not have to qualify the use of a type in that namespace:
using System.Data.Entity;
namespace MyNamespace
{
// Your code
}
Using directives are typically placed at the top of your file, but they can be placed at the top of your namespace as well.
namespace MyNamespace
{
using System.Data.Entity;
// Your code
}
For more information on using directives, see: using Directive (C# Reference)
A note about references: Before you can use System.Data.Entity
, you'll need to add a reference to the EntityFramework.dll. NuGet is a great tool for this, and can be invoked using the Visual Studio Package Manager.
Using Alias Directive
To create an alias for a namespace or a type. This is called a using alias directive:
using Project = PC.MyCompany.Project;
For more information on using alias directives, see: using Directive (C# Reference)
Using Statement
Provides a convenient syntax that ensures the correct use of IDisposable objects:
using (var font1 = new Font("Arial", 10.0f))
{
byte charset = font1.GdiCharSet;
}
For more information on using statements, see: using Statement (C# Reference)
james
Updated on July 16, 2022Comments
-
james almost 2 years
I am new to Visual Studio and C# in general. I'm following a tutorial trying to learn the language (tutorial here).
One of the steps is to add a “using” statement to the System.Data.Entity namespace at the top of the class file (in order to reference the DbContext and DbSet classes). This can be found under step 3.
I'm hoping someone can help me out with this section. I've searched on here and Google for an answer, but since I'm new to the language I can't seem to find the correct answer. Any help would be greatly appreciated!