Sorry if there is a clear answer for this. But I canβt insert into a simple table because it contains a foreign key.
Task table
TaskId (PK) Description StatusId (FK)
In which I am trying to insert like this:
Task t = new Task(); t.Id = 1234; t.Title = "foo"; t.Status = db.Status.ToList().First();
But get an updateException error: <i> A link is being added or removed from the association "FK_Task_Status". With power limitations, you must also add or remove the corresponding "Task".
How can I insert into this table?
Greetings
....
Found my problem ....
My circuit was wrong. When I created my foreign key, I pointed to the wrong field. If you look in the SQL profiler, you see this:
SELECT 1 AS [C1], [Extent1]. [Id] AS [Id], [Extent1]. [Descr] AS [Descr], [Extent2]. [Id] AS [Id1] FROM [dbo]. [Status] AS [Extent1] LEFT OUTER JOIN [dbo]. [Task] AS [Extent2] ON [Extent1]. [Id] = [Extent2]. [Id]
What should this be (joining statusId not id):
SELECT 1 AS [C1], [Extent1]. [Id] AS [Id], [Extent1]. [Descr] AS [Descr], [Extent2]. [Id] AS [Id1] FROM [dbo]. [Status] AS [Extent1] LEFT OUTER JOIN [dbo]. [Task] AS [Extent2] ON [Extent1]. [Id] = [Extent2]. [StatusId]
Stupid me;)
source share