Ich habe die Lösung erneut erstellt.
Code: Select all
File > New > Project > VisualC# > Console Application
Name : teststudent
Solution name : teststudent
Code: Select all
Add > New Item > ADO.Net Entity Data Model > Generate from database
Code: Select all
save entity connection settings in App.Config as :
teststudententities
Code: Select all
6.0
Code: Select all
Model Namespace:
teststudentModel
Ich versuche, eine Abfrage zu erstellen, um alle Datensätze in einer Datenbanktabelle mit dem Namen anzuzeigen Students in Visual Studio 2013.
studentdb ist der Name meiner Datenbank. Ich habe eine Verbindung zu meiner SQL Server-Datenbank hergestellt. Ich kann die Tabellen des Modells im Lösungs-Explorer sehen. Wenn ich es ausführe, erhalte ich einen Build-Fehler:
Code: Select all
'studentdb' is a 'namespace' but is used like a 'type'
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace studentdb
{
class Program
{
static void Main(string[] args)
{
Query1();
}
private static void Query1()
{
using (var context = new studentdb())
{
var students = from studentdetails in context.students select studentdetails;
Console.WriteLine(" Query All students");
foreach (var student in students)
{
Console.WriteLine("{0} {1}", student.studentid, student.surname);
}
Console.Write("Press enter to exit"); Console.ReadLine();
}
}
}
}