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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:18:14+00:00 2026-05-28T04:18:14+00:00

I have a class which inherit from DropCreateDatabaseIfModelChanges. public class SetupData : DropCreateDatabaseIfModelChanges<CyclingClubContext> {

  • 0

I have a class which inherit from DropCreateDatabaseIfModelChanges.

public class SetupData : DropCreateDatabaseIfModelChanges<CyclingClubContext>
{
    protected override void Seed(CyclingClubContext context)
    {
        var _CycleType = new List<CycleType>
        {
            new CycleType { Type = "Leisure Cycle Type A" },
            new CycleType { Type = "Mountain Bike Type A" },
            new CycleType { Type = "Racer" },
            new CycleType { Type = "Leisure Cycle Type B" },
            new CycleType { Type = "Mountain Bike Type B" }                
        };            

        new List<CycleModel>
        {
            new CycleModel{ Model = "Challenge 26in", CycleType =  _CycleType.Single(r => r.Type == "Racer") },
            new CycleModel{ Model = "Challenge 27in", CycleType =  _CycleType.Single(r => r.Type == "Racer") },
            new CycleModel{ Model = "Muddy Fox Vortex", CycleType =  _CycleType.Single(r => r.Type == "Leisure Cycle Type A") },
            new CycleModel{ Model = "Laser 8", CycleType =  _CycleType.Single(r => r.Type == "Leisure Cycle Type B") },
            new CycleModel{ Model = "Silverfox 26in", CycleType =  _CycleType.Single(r => r.Type == "Mountain Bike Type B") }
        }.ForEach(IndividualRow => context.CycleModel.Add(IndividualRow));
    }        
}

After I run this class, I found that …
Two tables created.
1)Cycle Model (all row inserted correctly).
2)Cycle Type (One row left to insert)[Problem].

Mountain Bike Type A is not insert to table CycleType.
I think , I need to modify my code but I don’t know how could I do it.

I don’t want to insert another row like below so that it can solve my problem.

new CycleModel{ Model = "Testing...", CycleType =  _CycleType.Single(r => r.Type == "Mountain Bike Type A") }

Please let me get suggestion.

  • 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-28T04:18:15+00:00Added an answer on May 28, 2026 at 4:18 am

    A Seed() method should end with a context.SaveChanges().

    As it stands now it’s strange anything is saved at all.

    But it’s clear that “Mountain Bike Type A” is not referenced by any CycleModel and that is why it’s left out.

    You can probably fix it with

     _CycleType.ForEach(IndividualRow => context.CycleType.Add(IndividualRow));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a Web Service context, I have the following class which inherit from the
I have made a class which a form can inherit from and it handles
I have a MustInherit Parent class with two Child classes which Inherit from the
I have an abstract class User and 2 classes which inherit from it, namely
I have a class which I intend for others to inherit from. It has
I have set of classes which inherit from a single super class: Super |
I have a class which inherits from QTreeWidgetItem and I intercept the click event.
I have a class which inherits from Canvas. On the OnRender method I draw
I have my class X which inherits from Qt's class Base . I declared
I have a class B which inherits from A which in turn derives from

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.