我正在尝试使用Oracle数据库在c#中插入记录。我正在使用事务进行插入。
如何在即将出现的下一个对象的数据中插入子对象ID?我能够获取父级的ID但无法获取子对象ID。父母和孩子是同一类的对象。
代码如下所示:
using (DatabaseContext lContext = new DemoDatabaseContext())
{
try
{
foreach (var alias in pLstAlias)
{
DATA lAlias = new DATA();
lAlias.ID = alias.ID;
lAlias.FIRST_NAME = alias.FIRST_NAME;
lAlias.SECOND_NAME = alias.SECOND_NAME;
lAlias.NAME_CONCAT = alias.GetConcatName();
lAlias.SYSTEM_NAME = alias.GetSystemName(lAlias.NAME_CONCAT);
lAlias.Add(lContext);
if (alias.AKAList != null)
{
foreach (var aka in alias.AKAList)
{
DATA lChildAlias = DATA();
lChildAlias.PARENT_ID = lAlias.ID;
lChildAlias.AKA__NAME = aka.FIRST_NAME;
lChildAlias.NAME_CONCAT = aka.GetConcatName();
lChildAlias.SYSTEM_NAME = aka.GetSystemName(lChildAlias.NAME_CONCAT);
List<DATA2> aliasList = StoreRecodsToObject(lChildAlias.SYSTEM_NAME);
if (aliasList != null)
{
foreach (var item in aliasList)
{
DATA DataForAliases = new DATA2();
// here I need to add ID of lChildAlias
DataForAliases.ALIAS_ID = lChildAlias.ID;
DataForAliases.NAME = item.NAME;
DataForAliases.Add(lContext);
}
}
}
lChildAlias.Add(lContext);
}
}
}
}
catch(Exception ex){
lContext.Rollback();
return false;
}
}