Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Creating Items For Two Related Tables #7717


User avatar
0
erkateknoloji created

(angular, 7.0.0, .net core)

Merhaba,

Foregin Key ve aralarında 1:M (one to many) ilişki olan 2 tabloya aynı method içerisinde kayıt atmak istiyoruz.

Örneğin; Country tablosuna "CountryId"=1(pk) "CountryName"="Türkiye" City Tablosuna "CityId"=1(pk) CountryId="1" "CityName"="İstanbul" City Tablosuna "CityId"=2(pk) CountryId="1" "CityName"="Ankara" City Tablosuna "CityId"=3(pk) CountryId="1" "CityName"="İzmir"

Application katmanında bunu create event'inde yapmak istediğimiz zaman country insert işlemi henüz commit'lenmediği için hata alıyoruz. (UnitofWork commit'le denememize rağmen)

Varsa bir örnek paylaşabilir misiniz? Teşekkürler


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @erkateknoloji

    You have to call await CurrentUnitOfWork.SaveChangesAsync(); or CurrentUnitOfWork.SaveChanges(); right after inserting Country record to database to get Id of new Country.

    If you have tried that, could you share your app service code for us to check ?

    Thanks,

  • User Avatar
    0
    ismcagdas created
    Support Team

    This issue is closed because of no recent activity. Please open a new issue if you are still having this problem.