Entity SQL reference to the created model in C#

78 Views Asked by At

I am trying to follow a textbook tutorial, I create the model but I don't know why I cannot reference to it. Anyway, in collusion when I try to read the data from the database I get an exception, saying that the table was not found. Thank you for any help and advice.

My Code:

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));
   }
}

Exception:

enter image description here

My Model:

enter image description here

0

There are 0 best solutions below