Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7790027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:27:50+00:00 2026-06-01T21:27:50+00:00

I am new the code-first Entity Framework. I have tried a few things now,

  • 0

I am new the code-first Entity Framework.

I have tried a few things now, but can’t get EF to construct any tables in the my SQL Azure database.
Can anyone advise of some steps and settings I should check.

The membership provider has no problems create it’s tables.

I have added the PersistSecurityInfo=True in the connection string. The connection string is using the main user account for the server.

When I implement the tables in the database using sql everything works fine.

I have the following in the WebRole.cs

            //Initialize the database
        Database.SetInitializer<ReykerSCPContext>(new DbInitializer());

My DbInitializer (which does not get run before I get a “Invalid object name ‘dbo.ClientAccountIFAs’.” when I try to access the table for the first time. Sometime after startup.

    public class DbInitializer:DropCreateDatabaseIfModelChanges<ReykerSCPContext>
{
    protected override void Seed(ReykerSCPContext context)
    {
        using (context)
        {
            //Add Doc Types
            context.DocTypes.Add(new DocType() { DocTypeId = 1, Description = "Statement" });
            context.DocTypes.Add(new DocType() { DocTypeId = 2, Description = "Contract note" });
            context.DocTypes.Add(new DocType() { DocTypeId = 3, Description = "Notification" });
            context.DocTypes.Add(new DocType() { DocTypeId = 4, Description = "Invoice" });
            context.DocTypes.Add(new DocType() { DocTypeId = 5, Description = "Document" });
            context.DocTypes.Add(new DocType() { DocTypeId = 6, Description = "Newsletter" });
            context.DocTypes.Add(new DocType() { DocTypeId = 7, Description = "Terms and Conditions" });


            //Add ReykerAccounttypes
            context.ReykerAccountTypes.Add(new ReykerAccountType() { ReykerAccountTypeID = 1, Description = "ISA" });
            context.ReykerAccountTypes.Add(new ReykerAccountType() { ReykerAccountTypeID = 2, Description = "Trading" });
            context.ReykerAccountTypes.Add(new ReykerAccountType() { ReykerAccountTypeID = 3, Description = "SIPP" });
            context.ReykerAccountTypes.Add(new ReykerAccountType() { ReykerAccountTypeID = 4, Description = "CTF" });
            context.ReykerAccountTypes.Add(new ReykerAccountType() { ReykerAccountTypeID = 5, Description = "JISA" });
            context.ReykerAccountTypes.Add(new ReykerAccountType() { ReykerAccountTypeID = 6, Description = "Direct" });
            context.ReykerAccountTypes.Add(new ReykerAccountType() { ReykerAccountTypeID = 7, Description = "ISA & Direct" });

            //Save the changes
            base.Seed();
        }

and my DBContext class looks like

    public class ReykerSCPContext : DbContext
{
    //set the connection explicitly
    public ReykerSCPContext():base("ReykerSCPContext"){}

    //define tables
    public DbSet<ClientAccountIFA> ClientAccountIFAs { get; set; }
    public DbSet<Document> Documents { get; set; }
    public DbSet<DocType> DocTypes { get; set; }
    public DbSet<ReykerAccountType> ReykerAccountTypes { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        //Runs when creating the model. Can use to define special relationships, such as many-to-many.

    }

The code used to access the is

        public List<ClientAccountIFA> GetAllClientAccountIFAs()
    {
        using (DataContext)
        {

            var caiCollection = from c in DataContext.ClientAccountIFAs
                                select c;

            return caiCollection.ToList();
        }
    }

and it errors on the last line.
Help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:27:51+00:00Added an answer on June 1, 2026 at 9:27 pm

    The problem here transpired to be mixed up with the Universal Membership Provider I was using.
    The membership provider was instantiating the database before Entity Framework, so that each time EF thought the database existed and did not try to drop it.

    To solve this I made sure that not only did I set the initializer in the OnStart method of the WebRole.cs, but to also force a query to the DbContext too.

    This then forced the database to be created prior to the membership tables and all was well.
    Once the membership provider is called for the first time, it creates the tables that are necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Entity Framework Code First is a great framework for developing new projects. But what
I am creating a new database model using Entity Framework 4.3 Code-FIrst; using Fluent
I have a database that was created with the Entity Framework's code first approach.
My DAL is based on Entity Framework Code First. I have a post model
I have the following hierarchy of objects in Entity Framework Code First: class Parent
I'm trying to get Entity Framework Code First to create a database for me
I wish to use Entity Framework Code-first for a new project. So i decided
I really like the Entity Framework Code First idea because I can rapidly prototype
I am using Entity Framework 4.1 code first and ASP.NET MVC 3. I have
I am working with Entity Framework Code first. I have a simple model: public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.