Inserting into tables w/ FK relationship fails inside Migrations.cs

Here's the code from Migrations.cs. First I create the schema, then FK, then try to insert the data into the parent table first, and then the child table. This code works if I just do the insert into the parent table. But if I do the inserts to both tables
I get FK errors, which leads me to believe Orchard or NHibernate is for some reason attempting inserts into the child table in parallel or before the parent table inserts are done.

I tried IRepository<>.Flush() and IContentManager.Flush() after the parent table inserts but that didn't help.

Actually, running into a new problem now that I fixed the above issue. Looks like NHibernate doesn't want to insert the value I set manually for "Id" property. See the sql statement in the error below, Id column is missing. I have already modified the migrations
.cs as such:

That's what I was doing at first (I have the .Identity() call in the OP), but I actually want to set the Id's myself. I will need to periodically tie these back to an external data source and don't want to complicate things by having to maintain diff set
of mappings between the Orchard db and the original db.

I just checked right now and it's not set to identity. You're right, it would be a different error. The error message in my 3rd post shows that NHibernate is for some reason not trying to insert any value for Id column. I'm not that familiar with NHibernate
so not sure how to best debug this.

I don't know enough about NHibernate, but I suspect that you would have to create your own alteration in order to configure your primary key. Alternatively, you could inherit your entity record from ContentPartRecord (but I suspect you're not going to want
to do that)

I'm interested to try that out, but for now I just went with "Id" columns for the PK's, an "ParentId" cols in both tables, indexed to aid the join, but w/o FK relationship. Referential integrity isn't that big a deal since this data won't be edited frequently,
and possibly never through the UI. We'd know pretty quickly if the integrity were violated.

Would I just create a class that implements IAutoMappingAlteration? How does NHibernate scan and pick that up in order to run my Override code?