Code First Entity Framework and Windows Azure SQL
===

I am trying move a very simple code first example from my local SQL on to Azure SQL and as it appears I've hit a brick wall.

This is the simple code that I am using:

    public class Cat
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid ID { get; set; }
        public string Name { get; set; }
    }

    **Context class:**

    public class CatDbContext : DbContext
    {
        public PersonDbContext()
            : base("name=MyConnectionString")
        { }
        public DbSet<Cat> Cats { get; set; }
    }

    My connection string:
     <add name="MyConnectionString" connectionString="Server=tcp:xxxx.database.windows.net;Database=xxxx;User ID=xxxx@xxxx;Password=xxxx;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient" />

Now I have a simple console app which does the following:

            CatDbContext db = new CatDbContext();
            db.Cats.Add(new Cat { Name = "Garfield", ID = Guid.NewGuid() });
            db.SaveChanges();

And I am getting an exception at line db.SaveChanges(); saying:
Invalid object name 'dbo.Cats'.

Stack trace:

    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
    at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
    at System.Data.SqlClient.SqlDataReader.get_MetaData()
    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
    at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
    at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
    at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
    at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)

And no tables are created.
I will be very thankful if someone could point me in the right direction, as I have no clue why this is happening.

Kind regards,
Audrius.


  