0

I'm new to EF 6 and I'm getting an error;

'The context cannot be used while the model is being created.'

I have a console app and in the App.Config I have the following;

<connectionStrings>
    <add name="MemberFollowupEmailContext" connectionString="Data Source=Dev1;Initial Catalog=dbPublicDev;Persist Security Info=True;User ID=*****;Password=******" providerName="System.Data.SqlClient" />
</connectionStrings>

Then I have a class for the Context;

namespace MemberFollowupEmails
{
    public class MemberFollowupEmailContext : DbContext
    {
        public DbSet<tblMemberFollowupEmail> MemberFollowupEmails { get; set; }

    }
}

In my program.cs I have;

    static void Main(string[] args)
    {
        MemberFollowupEmailContext db = new MemberFollowupEmailContext();

        var a = db.MemberFollowupEmails;

    }

However I am constantly getting the exception when I look at (a);

{"The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe."}

What do I need to do to be able to CRUD to my database from the console app?

griegs
  • 22,624
  • 33
  • 128
  • 205

0 Answers0