3

I'm building a form website using ASP.NET MVC and Entity Framework which collects information about companies (company_id (PK), name, location, processes, etc).

I have two tables, first is for the company data and the second is for process data (company_id (FK), process_id (PK), process_name, process_definition).

Where I'm stuck is, all instances of all companies and processes are loaded in the website (I believe this will work terribly when more data is involved). I want to have a 2 step process where at first the user enters company data, and after that the company_id is taken and the next page is the process data form, which is of the given company_id.

After the first form is filled, I want to just deal with the given companies data, and not load all of the companies in the DbSet. All of this is beyond my level of knowledge and I'm unable to articulate and find examples of what I want to do. I'm unable to share code snippets due to confidentiality. I'd appreciate if you can point me to similar projects or related resources.

I have tried to do what I can and currently I have two working forms for company and processes. It is working but not ideal, as stated above.

Edit:

CREATE TABLE [dbo].[Companies]
(
    [CompanyID] [smallint] NOT NULL,
    [CompanyName] [nvarchar](max) NULL,
    
    PRIMARY KEY CLUSTERED ([CompanyID] ASC)
                WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
                      IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, 
                      ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[Processes]
(
    [ProcessNo] [smallint] NOT NULL,
    [CompanyID] [smallint] NOT NULL,
    [ProcessName] [nvarchar](max) NULL,
    [Description] [nvarchar](max) NULL,

    PRIMARY KEY CLUSTERED ([ProcessID] ASC, [ProcessNo] ASC)
                WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
                      IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, 
                      ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[Processes] WITH CHECK 
    ADD FOREIGN KEY([CompanyID]) REFERENCES [dbo].[Companies] ([CompanyID])
GO
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

I am guessing you are not showing any code because you are lost. That said some code would be helpful.
First question do you understand FOREIGN KEY? Show us how you created the database tables in code please

CREATE TABLE customers (
customer_id int PRIMARY KEY, 
. . . 
FOREIGN KEY(customer_id) REFERENCES customer_leads(customer_lead_id)

);

Vector
  • 3,066
  • 5
  • 27
  • 54
  • I've edited as per your request. I'm not allowed to share specifics of the actual database, but to say I'm lost is true also. Thanks for answering. – vesadeceeger Apr 08 '23 at 23:52
  • 1
    @vesadeceeger I do not use asp.net so have a look at this link below https://stackoverflow.com/questions/937732/getting-the-foreign-key-constraints-of-a-table-programatically and consider this for a search vb.net extract data from datatable with foreign key constraint – Vector Apr 09 '23 at 00:11
  • 1
    @vesadeceeger have a look at this link or post your question here https://www.codeproject.com/Questions/5357705/Compare-two-datatables-in-Csharp – Vector Apr 10 '23 at 20:10