I have two model classes (Tickets
and Activities
), where Activities
is more like a look-up table, and is not suppose to hold any navigational properties or FK's of other entities.
A record in Tickets
is supposed to have a single Activity
, but in the whole table of Tickets
, there will be many of the same Activities
. Activities needs to be a table, and not (for example) an enum, because of the possibility of future updates and amendments.
Although this seems trivial enough, I keep encountering errors like Identity is Set to off
.
My models:
public class Tickets
{
public int ID {get; set;}
// fk
public int ActivityID {get; set;
// nav property
public Activity Activity {get; set;}
// other properties.
}
public class Activity
{
public int ID {get; set;}
public int RankOrder {get; set;}
//other properties
}
I have specified a domainmapping for the Tickets
model:
builder.HasOne(t => t.Activity)
.WithMany()
.HasForeignKey(t => t.ActivityID);
based on this SO-post and blogpost: here and here but I don't get it to work, my most recent error message is:
SqlException: Cannot insert explicit value for identity column in table 'Activity' when IDENTITY_INSERT is set to OFF.
Also, with this mapping it seems that EF created a Ticket column in the Activity table, something that I don't want.