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 6698737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:36:48+00:00 2026-05-26T06:36:48+00:00

I have the following code I created with help of asp.net mvc tutorials. These

  • 0

I have the following code I created with help of asp.net mvc tutorials.
These are in a different class library I called Model.
I created an app.config in the class library with the connection string called HRContext.
Also on the webproject I created the same connection string.

When I run the project, I put breakpoints and the Seed method is never executed, however the OnModelCreating is being executed.

I got an exception saying that the table dbo.Position does not exist in the view.

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.Position'.



Line 21:             var positions = unitOfWork.PositionRepository.Find(p => p.PositionID != null);
Line 22: 
Line 23:             return View(positions.ToList());
Line 24:         }








 public class HRContextInitializer : DropCreateDatabaseAlways<HRContext>
    {
        protected override void Seed(HRContext context)
        {
            Position netdeveloper = new Position() { name = ".net developer", yearsExperienceRequired = 5 };
            Position javadeveloper = new Position() { name = "java developer", yearsExperienceRequired = 5 };

            byte[] johnImage = File.ReadAllBytes(@"\Content\Photos\1.jpg");
            byte[] luisImage = File.ReadAllBytes(@"\Content\Photos\2.jpg");

            Applicant luis = new Applicant()
            {
                name = "Luis",
                skypeuser = "le.valencia",
                telephone = "0491732825",
                photo = luisImage
            };

            Applicant john = new Applicant()
            {
                name = "John",
                skypeuser = "jo.valencia",
                telephone = "3435343543",
                photo = johnImage
            };


            ApplicantPosition appicantposition = new ApplicantPosition()
            {
                Applicant = luis,
                Position = netdeveloper,
                appliedDate = DateTime.Today,
                Status = Status.Applied
            };

            ApplicantPosition appicantposition2 = new ApplicantPosition()
            {
                Applicant = john,
                Position = javadeveloper,
                appliedDate = DateTime.Today,
                Status = Status.Applied
            };

            context.Positions.Add(netdeveloper);
            context.Positions.Add(javadeveloper);
            context.Applicants.Add(luis);
            context.Applicants.Add(john);
            context.ApplicantsPositions.Add(appicantposition);

            context.SaveChanges();
        }
    }




public class HRContext : DbContext
    {
        public DbSet<Position> Positions { get; set; }
        public DbSet<Applicant> Applicants { get; set; }
        public DbSet<ApplicantPosition> ApplicantsPositions { get; set; }
        public DbSet<ApplicationPositionHistory> ApplicationsPositionHistory { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Position>().ToTable("Position");
            modelBuilder.Entity<Applicant>().ToTable("Applicant");
            modelBuilder.Entity<ApplicantPosition>().ToTable("ApplicantPosition");
            modelBuilder.Entity<ApplicationPositionHistory>().ToTable("ApplicationsPositionHistory");

            modelBuilder.Entity<Position>().Property(c => c.name).IsRequired();
            modelBuilder.Entity<Applicant>().Property(c => c.name).IsRequired();
            modelBuilder.Entity<ApplicantPosition>().Property(c => c.appliedDate).IsRequired();

            base.OnModelCreating(modelBuilder);
        }
    }
  • 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-05-26T06:36:49+00:00Added an answer on May 26, 2026 at 6:36 am

    You need to tell EF to use your custom inializer with the Database.SetInitializer method. The best to call it at your application start (if you are using MVC then in the Application_Start). But you should only call it once and before you access your context for the first time

    protected void Application_Start()
    {
         ...
        Database.SetInitializer(new HRContextInitializer());
         ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code in c#. I'm using ASP.NET MVC 3. public override
I'm fairly new to ASP.NET MVC and am looking for help with the following
I have a transparent BufferedImage created with the following code(not relevant how it is
I have created an alert view with two buttons using the following code: UIAlertView
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have the following code that creates a serverside object of the xmlhttp class.
I 'm new to the asp.net. I have created one web page in that
i have textbox controls that are created dynamically in the ASP.NET. I want to
I have created an SSISpackage in my asp.net project.To call the ssis package, i

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.