I'm creating a new application for creating and transporting reports in ASP.NET Core. So, I used entity framework to to create a database using code first. However, one of the classes called "WfStepsDefinition" does not let a foreign key called "WfDefinitionId" have repeating values.
I checked the database by reading the create statement and using queries to insert the appropriate data. So, I don't believe the problem is rooted in database constraints.
Here is the two values I'm using dbcontext.SaveChangesAsync() on that returns errors:
new WfStepsDefinition() { Ordr = 1, WfDefinitionId = 1, WfStepTypeId = 1},
new WfStepsDefinition() { Ordr = 1, WfDefinitionId = 1, WfStepTypeId = 1}
Here are two values I'm using dbcontext.SaveChangesAsync() on that do not returns errors:
new WfStepsDefinition() { Ordr = 1, WfDefinitionId = 1, WfStepTypeId = 1},
new WfStepsDefinition() { Ordr = 1, WfDefinitionId = 2, WfStepTypeId = 1}
Here is the class for WfStepsDefinitions while this would traditionally be a use a composite primary key it inherits from a base entity that includes Id as a primary key and other values:
public class WfStepsDefinition : Entity
{
public int Ordr { get; set; }
// n-1 relationship
public int WfDefinitionId { get; set; }
public WfDefinition WfDefinition { get; set; }
public int WfStepTypeId { get; set; }
public WfStepType WfStepType { get; set; }
}
For reference this SQL statement is how it is used in the database
SELECT TOP (1000) [Id]
,[UpdatedBy]
,[UpdatedOn]
,[Ordr]
,[WfDefinitionId]
,[WfStepTypeId]
FROM [Pwdx].[dbo].[WfStepsDefinition]
For expected results I should be able to use repeating values for WfDefinitionId such as
new WfStepsDefinition() { Ordr = 1, WfDefinitionId = 1, WfStepTypeId = 1},
new WfStepsDefinition() { Ordr = 1, WfDefinitionId = 1, WfStepTypeId = 1}
should not return any errors
This is the last batch from the output before the IIS exits.
Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT CASE
WHEN EXISTS (
SELECT 1
FROM [WfStepsDefinition] AS [w])
THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT)
END
The program '[31648] iisexpress.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
EDIT: Figured something out
public class WfDefinition : Entity
{
public string Description { get; set; }
// n-1 relationship
public int PwReleaseTypeId { get; set; }
public PwReleaseType pwReleaseType { get; set; }
// 1-n relationships
//public List<WfStepsDefinition> WfStepsDefinitions { get; set; } = new List<WfStepsDefinition>();
}
how come the error goes away when the reference to the 1-n class is removed?
User contributions licensed under CC BY-SA 3.0