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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:07:57+00:00 2026-05-17T21:07:57+00:00

first some background. Here is the SQLite script I created: create table Person( ID

  • 0

first some background. Here is the SQLite script I created:

create table Person(
ID integer not null primary key autoincrement,
Name text not null
);

create table Department(
ID integer not null primary key autoincrement,
Name text not null,
Leader integer not null references Person(ID)
);

It generates the following Entity Framework model:

alt text

Here, I’m trying to create make a simple application so I can learn how to use SQLite, so I can save a new Person to the database, and also save a new department. A department can have only 1 leader, and a person can be leader of many departments.

Right now I’m focusing on creating a new department.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SQLite_Testing_Grounds
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            LoadUsersToComboBox();
        }

        private void LoadUsersToComboBox()
        {
            throw new NotImplementedException();
        }

        private void button2_Click(object sender, EventArgs e)
        {            
            CreateNewPerson();
        }

        private void CreateNewPerson()
        {
            if (textBox2.Text != String.Empty)
            {
                ScansEntities1 db = new ScansEntities1();
                Person user = new Person()
                {
                    Name = textBox1.Text
                };

                db.AddToPeople(user);
                db.SaveChanges();
            }            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            CreateNewDepartment();
        }

        private void CreateNewDepartment()
        {
            if ((textBox1.Text != String.Empty) && (comboBox1.SelectedIndex >= 0))
            {
                ScansEntities1 db = new ScansEntities1();                            
                Department department = new Department()
                {
                    Name = textBox1.Text,
                    //Then what goes here? :/

                };
            }
            throw new NotImplementedException();
        }
    }
}

How can I save the ID of the selected “Person” using the ComboBox?

alt text

EDIT!

Following John H. advice, my Department class (generated by EF) doesn’t contain a definition for Leader (as I would expect if I were using MS SQL).

Here is a screenshot of what it does have. Thanks again for the massive help.
alt text

  • 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-17T21:07:57+00:00Added an answer on May 17, 2026 at 9:07 pm

    You need to stub out the person and attach it to the context use that stubbed person as reference for you LEADER in your Department Object.

    Stub Entities Reference Link

        private void CreateNewDepartment()
        {
            if ((textBox1.Text != String.Empty) && (comboBox1.SelectedIndex >= 0))
            {
                ScansEntities1 db = new ScansEntities1();
                Person person = new Person() {Id = /*SomeId*/};
                db.AttachTo("Person", person);
                Department department = new Department()
                {
                    Name = textBox1.Text,
                    Person = person
    
                };
                db.AddToDepartment(department);
                db.SaveChanges();
    
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's some background info. I have three MySQL tables (all InnoDB). The first table
As usual, some background information first: Database A (Access database) - Holds a table
First some background: VB.NET 2005 Application that accesses a MS-SQL back-end, using multiple Web
This is my first post here and I wanted to get some input from
First some background. I have a batch-type java process run from a DOS batch
First some brief background: I have an existing ASP.NET MVC 1 application using Entity
Here's some background on what I'm trying to do: Open a serial port from
First, some background: Our product needs to integrate with the Lotus Notes client by
I'm currently polling my CFReadStream for new data with CFReadStreamHasBytesAvailable . (First, some background:
I have a strange problem in my rich client application. Here is some background:

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.