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

  • Home
  • SEARCH
  • 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 8860471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:16:26+00:00 2026-06-14T15:16:26+00:00

I want the MachineRecord to contain a GroupRecord Id, like the following: MachineRecord Id

  • 0

I want the MachineRecord to contain a GroupRecord Id, like the following:

MachineRecord

Id
Name
Number
GroupRecord

GroupRecord

Id
Name

What I have tried:

I have tried to make the property in the model a
public virtual GroupRecord GroupRecord { get; set; }
and the database column name GroupRecord_Id, but somehow that won’t work, tried some other ways like giving the property the name GroupRecordId and the table column GroupRecord and so on, but all with no results.

So the question is, how to get this to work so the MachineRecord table contains a GroupRecord Id?

Machine.cs

namespace PowerAll.Voorraad.Models
{
  public class MachineRecord
  {
    public virtual int Id { get; set; }
    public virtual int MachineNumber { get; set; }
    public virtual string Title { get; set; }
    public virtual string Description1 { get; set; }
    public virtual string Description2 { get; set; }
    public virtual string Description3 { get; set; }
    public virtual string Description4 { get; set; }
    public virtual string Description5 { get; set; }
    public virtual string Description6 { get; set; }
    public virtual string SerialNumber { get; set; }
    public virtual GroupRecord GroupRecord { get; set; }
    public virtual char PriceType { get; set; }
    public virtual decimal Price { get; set; }
    public virtual int Year { get; set; }
  }
}

Group.cs

namespace PowerAll.Voorraad.Models
{
  public class GroupRecord
  {
    public virtual int Id { get; set; }
    public virtual string GroupName { get; set; }
  }
}

Migrations.cs

namespace PowerAll.Voorraad
{
  public class Migrations : DataMigrationImpl
  {
    public int Create()
    {
      SchemaBuilder.CreateTable("GroupRecord", table => table
        .Column<int>("Id", column => column.PrimaryKey().Identity())
        .Column<string>("GroupName", column => column.WithLength(100))
      );

      SchemaBuilder.CreateTable("MachineRecord", table => table
        .Column<int>("Id", column => column.PrimaryKey().Identity())
        .Column<int>("MachineNumber", column => column.NotNull())
        .Column<string>("Title", column => column.NotNull().WithLength(40))
        .Column<string>("Description1", column => column.WithLength(70))
        .Column<string>("Description2", column => column.WithLength(70))
        .Column<string>("Description3", column => column.WithLength(70))
        .Column<string>("Description4", column => column.WithLength(70))
        .Column<string>("Description5", column => column.WithLength(70))
        .Column<string>("Description6", column => column.WithLength(70))
        .Column<string>("SerialNumber", column => column.WithLength(20))
        .Column<int>("GroupRecord_id", column => column.NotNull())
        .Column<char>("PriceType", column => column.NotNull().WithLength(1))
        .Column<decimal>("Price", column => column.NotNull())
        .Column<int>("Year", column => column.WithLength(4))
      );

      // Return the version that this feature will be after this method completes
      return 1;
    }
  }
}

MachineController.cs

namespace PowerAll.Voorraad.Controllers
{
  [Themed]
  public class MachineController : Controller
  {
    private readonly IRepository<MachineRecord> machineRecords;

    public MachineController(IRepository<MachineRecord> MachineRecords) {
        machineRecords = MachineRecords;
    }

    public ActionResult List()
    {
        var items = machineRecords.Table;

        return View(items);
    }
  }
}

EDIT 2:

I came this far thanks to endorphin, but when I try to execute AddDummyData() I get this error: could not insert: [PowerAll.Voorraad.Models.MachineRecord][SQL: INSERT INTO PowerAll_Voorraad_MachineRecord (MachineNumber, Title, Description1, Description2, Description3, Description4, Description5, Description6, SerialNumber, PriceType, Price, Year) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()] While when I step trough the code all values are being posted right.

This is my AddDummyData():

public void AddDummyData()
{
  var GroupRecord = new GroupRecord { GroupName = "Oldtimers" };

  groupRecords.Create(GroupRecord);

  var MachineRecord = new MachineRecord
  {
    MachineNumber = 100001,
    Title = "Landini L25",
    Description1 = "Desc 1",
    Description2 = "Desc 2",
    Description3 = "Desc 3",
    Description4 = "Desc 4",
    Description5 = "Desc 5",
    Description6 = "Desc 6",
    SerialNumber = "100000",
    GroupRecord = GroupRecord,
    PriceType = 'I',
    Price = 7999.99m,
    Year = 1954
  };

  machineRecords.Create(MachineRecord);
}

EDIT 3:

Now it’s working, this is my working code (for those who are struggling on this too)

Migrations.cs

  public class Migrations : DataMigrationImpl
  {
    public int Create()
    {
      SchemaBuilder.CreateTable("MachineRecord", table => table
        .Column<int>("Id", column => column.PrimaryKey().Identity())
        .Column<int>("GroupRecord_Id")
        .Column<int>("MachineNumber", column => column.NotNull())
        .Column<string>("Title", column => column.NotNull().WithLength(40))
        .Column<string>("Description", column => column.WithLength(70))
        .Column<char>("PriceType", column => column.NotNull().WithLength(1))
        .Column<decimal>("Price", column => column.NotNull())
        .Column<int>("Year", column => column.WithLength(4))
      );

      SchemaBuilder.CreateTable("GroupRecord", table => table
        .Column<int>("Id", column => column.PrimaryKey().Identity())
        .Column<string>("Name")
      );

      return 1;
    }
  }

MachineRecord.cs

  public class MachineRecord
  {
    public virtual int Id { get; set; }
    public virtual int MachineNumber { get; set; }
    public virtual string Title { get; set; }
    public virtual string Description { get; set; }
    public virtual GroupRecord GroupRecord { get; set; }
    public virtual char PriceType { get; set; }
    public virtual decimal Price { get; set; }
    public virtual int Year { get; set; }
  }

GroupRecord.cs

  public class GroupRecord
  {
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
  }
  • 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-14T15:16:27+00:00Added an answer on June 14, 2026 at 3:16 pm

    The key to your problem is split across how you structure the models and how you define their relationship in the Migrations.cs.

    Here is a solution that I have used in the past.

    Firstly, the class which contains the link to the second class.

    public class CaptureRecord : ContentPartRecord {
       public virtual string CaptureName { get; set; }
       public virtual OptionsRecord OptionsRecord { get; set; }   
    }
    

    Note: inheriting from ContentPartRecord gives you an ID.

    Then the second class (in this case I do not need to inherit from ContentPartRecord so I add the ID myself)

    public class OptionsRecord {
      public virtual int Id { get; set; }
      public virtual string Name { get; set; }
    }
    

    In the Migrations.cs add the OptionRecord ID in the CaptureRecord table definition

    public class Migrations : DataMigrationImpl
    {
        SchemaBuilder.CreateTable("CaptureRecord",
                table => table
                .ContentPartRecord()
                .Column<string>("CaptureName")
                .Column<int>("OptionsRecord_id");
    
        SchemaBuilder.CreateTable("OptionsRecord",
                table => table
                .Column<int>("Id", column => column.PrimaryKey().Identity())
                .Column<string>("Name"));
    
        return 1;
    }
    

    Hopefully this will give you a push in the right direction in terms of how to structure the relationship between your two tables.

    Edit: To add content to this sort of structure you will need to manually manage this yourself using the IRepository instances.

    So in your controller AddDummyData gives an example of this.

     public class MachineController : Controller {
       private readonly IRepository<MachineRecord> _machineRecords;
       private readonly IRepository<GroupRecord> _groupRecords;
    
       public MachineController(IRepository<MachineRecord> machineRecords, IRepository<GroupRecord> groupRecords) {
         _machineRecords = machineRecords;
         _groupRecords = groupRecords;
       }
    
       public void AddDummyData(){
         // create a grouprecord in the database
         _groupRecords.Create(new GroupRecord { Id = 1, GroupName = "One" });
    
         // get the groupRecord just created (annoying that Create doesnt return the instance, 
         // but I dont know a way around this
         var groupRecord = _groupRecords
            .Fetch(x => x.Id == 1)
            .Single();
    
         // create a machine return with the grouprecord assigned to the GroupRecord property 
         _machineRecords.Create(new MachineRecord { 
            Id = 1,
            ..
            GroupRecord = groupRecord
         });
       }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Want make a mind map like the following: Image link is not available anymore.
Want to make a vocabulary list in HTML & CSS that looks like this:
Want to make a confirm box appear before someone leave my site. They have
Want to edit datatabase. I have tried this, but it doesn't work. def post(self,
Want to run javascript function from parent window in child window Example I have
want to know why String behaves like value type while using ==. String s1
want to have a Hyperlink-Button in a gridView in which I can display a
Want to code a key pad for an calculator. What I want to make
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
Want to verify that my understanding of how this works. Have a C++ Class

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.