在迁移期间,我如何插入到我的表中,然后检索 ID,然后使用它在另一个表中插入相关数据。
我现在拥有的是要插入的硬编码 ID,但我不知道当我运行迁移时它会是什么。
var contactId = 2;
var phoneNumber = 2;
Insert.IntoTable("Contacts")
.WithIdentityInsert()
.Row(new
{
Id = contactId,
TimeZoneId = contact.TimeZoneId,
contact.CultureId,
Type = (byte)(int)contact.Type,
Email = contact.Email.ToString(),
EntityId = entityId
});
Insert.IntoTable("PhoneNumbers")
.WithIdentityInsert()
.Row(new
{
Id = phoneNumberId,
phone.Number,
Type = (byte)(int)phone.Type,
ContactId = contactId
});
我希望能够检索插入的 ID 并将其用于第二次插入,而不是对其进行编码。
如果有任何帮助,我正在使用 SQL Server...
我认为这将是微不足道的,但似乎不是,在谷歌搜索之后,在这里没有看到任何答案。