hi
i am using LBLGen2.5.
I have a table structure
- Employee (PK=EmployeeID)
- EmployeeAssistant
EmployeeAssistant has 2 columns which are linked with Employee.EmployeeId column using (PK-FK) and these columns make a composite key. please see tables below
-------------------------------------------------------1------------------------------------------------
CREATE TABLE [dbo].[Employee](
[EmployeeId] [int] IDENTITY(1,1) NOT NULL,
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
(
[EmployeeId] ASC
)
) ON [PRIMARY]
-------------------------------------------------------2---------------------------------------------------
CREATE TABLE [dbo].[EmployeeAssistant](
[EmployeeId] [int] NOT NULL,
[EmployeeAssistantId] [int] NOT NULL,
CONSTRAINT [PK_EmployeeAssistant] PRIMARY KEY CLUSTERED
(
[EmployeeId] ASC,
[AssistantEmployeeId] ASC
)
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[EmployeeAssistant] WITH CHECK ADD CONSTRAINT [FK_EmployeeAssistant_Employee_For_Assistant] FOREIGN KEY([AssistantEmployeeId])
REFERENCES [dbo].[Employee] ([EmployeeId])
GO
ALTER TABLE [dbo].[EmployeeAssistant] CHECK CONSTRAINT [FK_EmployeeAssistant_Employee_For_Assistant]
GO
ALTER TABLE [dbo].[EmployeeAssistant] WITH CHECK ADD CONSTRAINT [FK_EmployeeAssistant_Employee_For_Employee] FOREIGN KEY([EmployeeId])
REFERENCES [dbo].[Employee] ([EmployeeId])
GO
ALTER TABLE [dbo].[EmployeeAssistant] CHECK CONSTRAINT [FK_EmployeeAssistant_Employee_For_Employee]
I want to add an employee assistant and this assitant assits multiple employees.
First i create a collection of EmployeeAssistant Enitity and add this collection in Employee Entity
My LLBLGEN Code:
EmployeeEntity Employee = new EmployeeEntity();
Employee.IsNew = true;
Employee.Name=”XYZ”;
foreach (ListItem item in lstEmployees.Items)
{
if (item.Selected)
{
EmployeeAssistantEntity EmployeeAssistant = new EmployeeAssistantEntity();
EmployeeAssistant.IsNew = true;
EmployeeAssistant.EmployeeId = int.Parse(item.Value);
Employee.EmployeeAssistant.Add(EmployeeAssistant);
}
}
when i call adapter.SaveEntity(Employee), System throws an exception
Cannot insert the value NULL into column 'AssistantEmployeeId', table 'dbo.EmployeeAssistant'; column does not allow nulls. INSERT fails.
The statement has been terminated
How to save an enitity with collection with such a composite keys relation?
Thanks