我正在尝试遵循教科书教程,我创建了模型,但我不知道为什么我不能参考它。无论如何,当我试图从数据库中读取数据时,我得到了一个异常,说找不到表。感谢您的任何帮助和建议。
我的代码:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.EntityClient;
using System.Data.Common;
using System.Data;
using System.Configuration;
//using StockHistoryModel; This is my model and is not available.
static void Main(){
string connectionString = ConfigurationManager.ConnectionStrings
["StockHistoryEntities"].ConnectionString;
EntityConnection connection = new EntityConnection(connectionString);
connection.Open();
EntityCommand command = new EntityCommand("SELECT SymbolID FROM Shares",
connection);
DbDataReader reader = command.ExecuteReader(
CommandBehavior.SequentialAccess);
while (reader.Read())
Console.WriteLine("{0}", reader.GetValue(0));
}
}
例外:
我的模型: